To add a static property to a class in C#, you simply need to use the static
keyword.
main.cs78 chars5 lines
In the above example, we've added a static property MyStaticProperty
to the class MyClass
. This property can be accessed using the class name, rather than an instance of the class.
main.cs70 chars3 lines
Note that static properties are shared across all instances of the class and can be accessed even if no instances of the class have been created.
gistlibby LogSnag