Cyan Cyan - 5 months ago 22
C# Question

Get the actual type from a Type variable

I am trying to get a type from a Type variable. For example:

Type t = typeof(String);
var result = SomeGenericMethod<t>();

An error happens on the second line, because
is not a
, it's a variable. Any way to make it a type?


No, you cannot know the value of a Type object at compile time, which is what you would need to do in order to use a Type object as an actual type. Whatever you're doing that needs to use that Type will need to do so dynamically, and not require having a type known at compile time.