C# Static classes cannot be instantiated and can only have static members. Static classes in C# are sealed and cannot contain instance constructors.
The following is an example containing static class and static members-
using System; public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} } class Program { public static void Main(string[] args) { Console.WriteLine("PI: "+Demo.PI); Console.WriteLine("Square: " + Demo.calc(3)); } }
Above, the static class is-
public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} }
Above we have the following static members -
public static float PI = 3.14f; public static int calc(int n){return n*n;}
The above is the detailed content of What are static classes in C#?. For more information, please follow other related articles on the PHP Chinese website!