Log in

View Full Version : C# - static



NDK
04-27-2010, 07:36 AM
When do we use static in c#?

I'm reading a book and i see this

static int val;
or

static void ShowDouble(){
...
}

But why do you use static en why don't you just write for example int val; ?

BLiZZaRD
04-27-2010, 07:52 PM
Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types.


From: http://msdn.microsoft.com/en-us/library/98f28cdx%28VS.71%29.aspx

NDK
04-28-2010, 12:24 PM
I found the same yesterday, but can someone explain it with his own words?

edit:
Found more information on this site:
http://www.daniweb.com/forums/thread96978.html#