To add a public static property to a class in C#, you can use the static
and get/set
keywords. Here's an example:
main.cs72 chars5 lines
In the above code, we have a class called MyClass
with a public static property called MyProperty
. This property can be accessed directly without creating an instance of the class, using the class name as follows:
main.cs120 chars6 lines
Note that static properties are shared across all instances of a class, meaning that if you change the value of a static property in one place, it will be reflected in all other places.
gistlibby LogSnag