The C # 5.0 language specification says:
Note that constants and nested types are classified as static members.
so if i write:
class A
{
int a;
class B
{
public void foo()
{
int j = a;
}
}
}
assignment a to j gives me error CS0120
"An object reference is required for a non-static field, method or 'member' property ''
therefore, I realized that it foois also implicit static.
However, when I look at both the decompiled code and the IL code, there is no pointer to a static keyword!
internal class A
{
private class B
{
public void foo()
{
}
}
private int a;
}
.class nested private auto ansi beforefieldinit B
extends [mscorlib]System.Object
{
.method public hidebysig
instance void foo () cil managed
{
}
...
}
Is a nested type a truly static type with all implicitly static methods?
source
share