Passing just a type as a parameter in C#
There are two common approaches. First, you can pass System.Type
object GetColumnValue(string columnName, Type type)
{
// Here, you can check specific types, as needed:
if (type == typeof(int)) { // ...
This would be called like: int val = (int)GetColumnValue(columnName, typeof(int));
The other option would be to use generics:
T GetColumnValue<T>(string columnName)
{
// If you need the type, you can use typeof(T)...
This has the advantage of avoiding the boxing and providing some type safety, and would be called like: int val = GetColumnValue<int>(columnName);
foo.GetColumnValues(dm.mainColumn, typeof(string))
Alternatively, you could use a generic method:
public void GetColumnValues<T>(object mainColumn)
{
GetColumnValues(mainColumn, typeof(T));
}
and you could then use it like:
foo.GetColumnValues<string>(dm.mainColumn);