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 Sergey Alexandrovich Kryukov 339
1 Nirav Prabtani 248
2 OriginalGriff 234
3 _Amy 165
4 Maciej Los 145
0 OriginalGriff 7,744
1 Sergey Alexandrovich Kryukov 6,956
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


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

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