In C#, a class is a blueprint for creating objects, providing initial values for member variables or properties, and implementations of member methods or functions. A class can have fields (variables), properties, constructors, methods, and events.
In C#, classes can be defined as either non-static or static. Non-static classes, also known as instance classes, can be instantiated and contain both static and instance members. They are useful for representing objects that have a specific state and behavior.
On the other hand, static classes are classes that cannot be instantiated and contain only static members. They are useful for holding utility methods and other functionality that is not specific to a particular instance of an object.
Static Classes
A static class in C# is a class that cannot be instantiated and contains only static members. For example, let us have a look at the MathHelper class:
public static class MathHelper
{
public static int Add(int a, int b)
{
return a + b;
}
}MathHelper class is a static class that contains a single static method, Add. Because it is a static class, you cannot create an instance of it using the “new” keyword. Instead, you can access its static members directly by using the class name:
int result = MathHelper.Add(2, 3); // Output: 5Non-Static Classes
A normal class (non-static class) can be instantiated and contains both static and instance members. As an example let us create a MathHelper class, but as a non-static one:
public class MathHelper
{
public int a { get; set; }
public int b { get; set; }
public MathHelper(int a, int b)
{
this.a = a;
this.b = b;
}
public int Add(int a, int b)
{
return a + b;
}
}To call the Add method you need to create a class object and call the Add method.
MathHelper mathHelper = new MathHelper(1, 2); mathHelper.Add(); // Output: 3Key differences
- Instance: A static class cannot be instantiated using the “new” keyword, while a normal class can.
- Members: A static class can only contain static members, while a normal class can contain both static and instance members.
- Inheritance: A static class cannot be inherited by other classes, while a normal class can be inherited.
- Accessibility: A static class can only be accessed through its static members, while a normal class can be accessed through both its static and instance members.
- Use cases: Static classes are typically used to hold utility methods and other functionality that is not specific to a particular instance of an object. On the other hand, normal classes are used to represent objects that have a specific state and behavior.
Overall, the choice between using a static class or a normal class will depend on the specific requirements of the application


