A non-static class can contain static methods, fields, properties, or events.
The static member is callable even when no instance of the class has been created.
The static member is always accessed by the class name, not the instance name.
Only one copy of a static member exists, regardless of how many instances of the class are created.
Static methods and properties cannot access non-static fields and events in their containing type.
Static methods can be overloaded but not overridden, because they belong to the class, and not to any instance of the class.
C# does not support static local variables.
Static members are initialized before the static member is accessed for the first time and before the static constructor is called.
You declare static class members by using the static
keyword before the return type of the member, as shown in the following example:
public class Automobile
{
public static int NumberOfWheels = 4;
public static int SizeOfGasTank
{
get
{
return 15;
}
}
public static void Drive() { }
public static event EventType RunOutOfGas;
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |