I'm fairly new to C# and wondered if it is possible, to call a function based on the variable it is assigend to? I'm know i could overload the function and pass the variable as parameter, but I just wondered if this is possible.
Example, convert a value from a datarow to the datatype it is assigned to.
private int myint;
private string mystr;
private DateTime mydate;
myint = assign(datarow, "number");
// calls this
private int assign (DataRow r, string columnname)
{
return Convert.ToInt32(r[columnname]);
}
mystring = assign(datarow, "name");
// calls this
private string assign (DataRow r, string columnname)
{
return Convert.ToString(r[columnname]);
}