Click here to Skip to main content
14,297,581 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to use static variable and method in c#
Posted
Comments
Sandeep Mewara 13-Sep-10 6:18am
   
If not MSDN... Google?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

http://msdn.microsoft.com/en-us/library/79b3xss3%28VS.80%29.aspx[^]

Refer this link it will helpful to you.

Cheers :)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

use static keyword.

public static int MyStaticVariable;

public static void MyStaticMethod()
{
}


:)
   
Comments
Kunal Chowdhury «IN» 13-Sep-10 6:34am
   
Good Answer.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Hi Sheetal,

Why don't you search on Google? You will find it over net very easily. Try to read any Book, which will answer your query.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

I think what he meant was how do you use static variables, not how to declare them. But if I'm wrong and you are indeed asking how to declare them, then.
public static int sv;
public static void sm()
{
}


You call static variables and method through the class name
MyClass.sm();
MyClass.sv = 90;


There is only one copy of the static variable per class during a single runtime. Hence, it is not attached to any object. Static variables are used as counters for how many objects of a class are dispatched or the common information to be shared among the objects of the same class or the constant of a class such as the PI Math constant.

If this is a school assignment, I hope this helps
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100