public class MyStaticClass
{
// Static private field
private static string mName="";
// Private instance field
private long mAge=0;
// Instance function, can only be reached by an
// instance of the class
public string GetAge()
{
return mAge;
}
// Static function
public static string GetName()
{
return mName;
}
// Static property
public static string Name
{
get { return mName; }
set { mName=value; }
}
}
// Anrop till en static function, behöver ingen instans
MyStaticClass.GetName();
// Anrop till en static property
MyStaticClass.Name="Per Hultqvist";
// Anrop till instansmetoden GetAge.
MyStaticClass mInstance=new MyStaticClass();
mInstance.GetAge();