add a public static property to a class in csharp

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.cs
public class MyClass
{
    public static int MyProperty { get; set; }
}
72 chars
5 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.cs
// Setting value of MyProperty
MyClass.MyProperty = 42;

// Getting value of MyProperty
int value = MyClass.MyProperty;
120 chars
6 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