To declare a member as a static type we add a prefix Static during the member declaration.
Syntax
- Class Class1
- {
- int a;//instace type
- static int b ;// static type
- }
An instance data member of a class is recreated each time when a new instance of the class is created and it is associated with that instance only.
Whereas a static data member of a class is not recreated with new instance creation, only one copy of it is shared by all the instances.
See the following figure.
Create a Console Application in C# in Visual Studio 2010. Add a class to the project, in other words Class1.cs. Write the code as shown in the figure.

Now create three instances of the Class1 in the Main Method in the Program.cs file. (See the figure.)

Debug the application and see the output.


Usman FareeedPosted Mar 29, 2016, 3:39 PM
Excellent Example sir
dillip_parhiPosted Jul 3, 2014, 4:06 AM
nice article. well written....