Click here to Skip to main content
11,645,349 members (78,680 online)
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 jyo.net 814
1 OriginalGriff 650
2 Sergey Alexandrovich Kryukov 438
3 CPallini 436
4 Afzaal Ahmad Zeeshan 418
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 703
2 Afzaal Ahmad Zeeshan 702
3 DamithSL 681
4 CPallini 595


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 13 Sep 2010
Copyright © CodeProject, 1999-2015
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