What is the static keyword in C#?
Answer
The static keyword indicates that a member belongs to the type itself rather than any instance. Static members: (1) Static field: one copy shared across all instances of the class — static int Count;. (2) Static method: callable without an instance — Math.Abs(), string.IsNullOrEmpty(). (3) Static class: cannot be instantiated, can only have static members — used as containers for utility methods (extension methods must be in static classes). (4) Static constructor: runs once before first use, initializes static members. (5) Static property: shared state. (6) Static using: using static System.Math; — allows calling Abs(-1) instead of Math.Abs(-1). Static state can lead to concurrency bugs if multiple threads access it — use thread-safe patterns (Interlocked, lock, immutable static fields). Prefer injected dependencies over static state for testability.