First declaration is static. This is just one physical object in the whole application domain.
If it is declared in some class; and the class has many instances, this field will be only one, accessible from any instance of a class itself. Same thing about structure.
Second declaration can mean different things. If can be a local variable, then it only exist on stack, accessible only withing the method where the variable is declared.
It also can mean instance variable of the class or a structure. If you created two instances of the same class or structure, there will be two different physical instances of
Number
. One instance can have
Number==2
, another one —
Number==132
, for example.
Let's see:
class MyClass {
internal MyClass(int number) {
this.Number = number;
StaticNumber = number * 2;
}
int Number;
internal static int StaticNumber;
}
MyClass first = new MyClass(1);
MyClass copy = first;
MyClass second = new MyClass(2);
For future: please read C# manual before asking questions like that (and also — before programming :-) ). There is no sense to try before you learn such most basic things.
—SA