Sobes.tech
Junior — Middle

Could you explain what is meant by static classes in programming?

sobes.tech AI

Answer from AI

In C#, a static class is a class that cannot be instantiated, meaning you cannot create an object of it. All members of such a class (methods, properties, fields) must be static. Static classes are typically used to group methods and data that do not depend on a specific object, such as utility functions.

Example of a static class:

public static class MathHelper
{
    public static int Square(int x) => x * x;
}

// Usage:
int result = MathHelper.Square(5); // 25

Main features:

  • Cannot create instances (new).
  • All members must be static.
  • Used for utility functions and constants.
  • The compiler prohibits inheritance from a static class and inheritance of a static class.