According to typeof documentation :
[...] To get the runtime type of an expression, you can use the .NET Framework method GetType
Therefore, this means that it typeofshould be an expression of compilation time.
The article on Type Type Parameters states that:
[...] The type argument for this particular class can be any type recognized by the compiler.
Any type recognized by the compiler is any type deduced by the compiler, that is, any type that is known at compile time.
If so, why is the following statement not allowed?
int value = GenericMethod<typeof(int)>();
source
share