Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
How to use static variable and method in c#
Posted 12-Sep-10 23:55pm
Comments
Sandeep Mewara at 13-Sep-10 6:18am
   
If not MSDN... Google?
Rate this: bad
good
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 Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use static keyword.
 
public static int MyStaticVariable;
 
public static void MyStaticMethod()
{
}
 
Smile | :)
  Permalink  
Comments
KunalChowdhury at 13-Sep-10 6:34am
   
Good Answer.
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 239
1 Sarvesh Kumar Gupta 185
2 George Jonsson 154
3 ArunRajendra 144
4 Richard MacCutchan 140


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 13 Sep 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid