0Pricing
C# Academy · Lesson

Static Classes for Utilities

Group helper functions in static classes.

What Is a Static Class?

A static class is declared with static class. It can contain only static members and cannot be instantiated. It is the natural home for utility functions.

using System;

static class StringUtils
{
    public static string Shout(string s) => s.ToUpper() + "!";
}

class Program
{
    static void Main()
    {
        Console.WriteLine(StringUtils.Shout("hello"));
    }
}

Cannot Create Instances

You never write new for a static class. All access goes through the class name directly.

using System;

static class MathUtils
{
    public static int Cube(int x) => x * x * x;
}

class Program
{
    static void Main()
    {
        // No instance needed
        Console.WriteLine(MathUtils.Cube(3));
    }
}

All lessons in this course

  1. Static Methods and Fields
  2. Static Classes for Utilities
  3. Constants and readonly Fields
  4. Static vs Instance Design
← Back to C# Academy