Differences between the Static and Non Static classes in C#

Image result for c#
C# methods and classes can have several statements in their declarations. You might be used to seeing them written something like this:

// Static Class
public static class exampleStaticClass
{}
// Static Method
public static int exampleStaticMethod()
{
    return 1;
}  


C# includes static keyword just like other programming languages such as C++, Java, etc. The static keyword can be applied on classes, variables, methods, properties, operators, events and constructors. However, it cannot be used with indexers, destructors or types other than classes.
The static modifier makes an item non-instantiable, it means the static item cannot be instantiated. If the static modifier is applied to a class then that class cannot be instantiated using the new keyword. If the static modifier is applied to a variable, method or property of class then they can be accessed without creating an object of the class, just use className.propertyName, className.methodName.
static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, we cannot use the new keyword to create a variable of the class type. ... Non-staticfields are local to each instance of an object.


Comments