Tuesday, May 8, 2012

Variable Return Type of a Method in C#

I want to give a parameter to a method and i want my method to return data by looking the parameter. Data can be in type of boolean, string, int or etc. How can i return a variable type from a method? I don't want to return an object type and then cast it to another type. For example:



BlaBla VariableReturnExampleMethod(int a)
{
if (a == 1)
return "Demo";
else if (a == 2)
return 2;
else if (a == 3)
return True;
else
return null;
}


The reason why i want that is i have a method that reads a selected column of a row from the database. Types of columns are not same but i have to return every column's information.





No comments:

Post a Comment