In the C# 5.0 language specification it 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; // ERROR
}
}
}
the assignment of a to j give me a CS0120 error
"An object reference is required for the nonstatic field, method, or property 'member'"
so I could understand that also foo
is implicit static.
However when I look both the decompiled code and IL code there is no indication of static keyword!
internal class A
{
private class B
{
public void foo()
{
}
}
private int a;
}
// Nested Types
.class nested private auto ansi beforefieldinit B
extends [mscorlib]System.Object
{
// Methods
.method public hidebysig
instance void foo () cil managed
{
}
...
}
Is a nested type really a static type with all methods implicitly static?
a
is an instance-member, isn´t it? – HimBromBeere Feb 4 '16 at 13:07