Passing Enum type as a parameter





0/5 (0 vote)
I think the start is wrong... we can pass types as parameters.A method like this:void ShowName(Type type){ Console.WriteLine(type.FullName);}can be called as:ShowName(typeof(object));or as this:ShowName(someObject.GetType());If you are trying to say that we can't...
I think the start is wrong... we can pass types as parameters.
A method like this:
void ShowName(Type type)
{
Console.WriteLine(type.FullName);
}
can be called as:
ShowName(typeof(object));
or as this:
ShowName(someObject.GetType());
If you are trying to say that we can't pass enum
types as type parameters, I will partially agree, as we can't use where T: enum
. But, you say that generic methods solve the problem, so that's not the case.
The only advantage (if that's really to be considered one) about using generic methods to pass types is that null
or open generic types (like List<>
without specifying a data type) will never be received. But doing the necessary if
s are probably faster than counting with the generation of the method.