Static fields methods properties
Context: Static members are shared across all instances of a class. They are accessed using the class name, not an instance.
Static Field
Section titled “Static Field”public class Counter{ public static int Count = 0; public Counter() => Count++;}Counter c1 = new Counter();Counter c2 = new Counter();Console.WriteLine(Counter.Count); // 2Static Method
Section titled “Static Method”public class MathHelper{ public static int Square(int x) => x * x;}int result = MathHelper.Square(5);Static Property
Section titled “Static Property”public class AppConfig{ public static string Environment { get; set; } = "Development";}Static Constructor
Section titled “Static Constructor”Called once before any static member is accessed.
public class Database{ static Database() => Console.WriteLine("Initialized");}