Declaring a member in a class as static is a member of a static member class, or static, or non-static, in general, a static member is a non-static member belonging to a class and is an instance object of a class. The following example code demonstrates how to declare a static and Non-static member
Program Listing 10-5
Using System;
Class Test
{
int x;
static int y;
void F ()
{
x = 1; Correct, equivalent to This.x = 1
y = 1; Correct, equivalent to Test.y = 1
}
static void G ()
{
x = 1; Error cannot access this.x
y = 1; Correct, equivalent to Test.y = 1
}
static void Main ()
{
Test T = new Test ();
T.x = 1; That's right
T.Y = 1; Errors cannot access static members in instances of a class
Test.x = 1; Error cannot access non-static members by class
Test.y = 1; Correct}}
A non-static member of a class belongs to an instance of a class. All instances of creating a class open an area in memory for Non-static members, and the class's static members belong to all instances of the class, regardless of how many replicas the class creates. A static member occupies only one area of memory.