The static keyword is used in C# to define static properties or methods. Static properties can be regarded as attributes of the class, and static methods can be regarded as methods of the class. Therefore, static properties and methods cannot be referenced in instantiated objects, and Neither static properties nor static methods can be qualified using the this keyword, but can only be qualified using the class name. Just use the class reference directly when calling static methods.
Static property example code:
public class Product
{
private static int count; //member
public static int Count //static property
{
get{ return Product.count; }
set{ Product.count = value; }
}
}
The syntax for declaring a static method is as follows:
Modifier static return type static method name (parameter list)