class MyClass
{
public void MyMethod(Type targetType = typeof(MyClass))
{
}
}
Isn't typeof(MyClass)
a compile-time constant?
I am not a IL expert, but seems that it calls a method at L_0005:
return typeof(int);
It´s the same of:
.maxstack 1
.locals init (
[0] class [mscorlib]System.Type typeofvar)
L_0000: ldtoken int32
L_0005: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
L_000a: stloc.0
L_000b: ldloc.0
L_000c: ret
You can see that it isn´t a constant writing type of code:
const Type constType = typeof(int);
That returns a error:
Constant initialize must be compile-time constant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With