#783 – When to Create a Static Class

A static class is a class that contains only static members and cannot be instantiated.  You don’t create an instance of the class, but rather just access its members directly.

    public static class DogUtil
    {
        public static void DoSomething()
        {
            Console.WriteLine("I'm doing something");
        }
    }
    public static class DogUtil
    {
        public static void DoSomething()
        {
            Console.WriteLine("I'm doing something");
        }
    }

You typically use a static class to hold a collection of methods that are utility methods and don’t need to act upon data that is persisted within a particular object.

As an example, the System.Math class in .NET contains a lot of math utility methods.  Each method operates in a stateless way.  That is, the method accepts one or more parameters, does some calculations, and returns a result.