Static classes are used in such cases where we need some utility functions and Properties. Utility functions are those functions which are very common in some software and everyone in that particular software is making use of those functions. so it does not make sense every time to create an object for such a class which is being used time to time by many programmers. You can take example of Built in Console Class of C# .
Static class does not allow user to create instances of the class as well as it restrict the user to inherit any data members/functions to derived class. So A static class can make your implementation simpler ,safe and faster because you do not have to create an object in order to invoke its methods.
to access a particular class from anywhere inside the solution and no need to create object to access it just use it directly.
If you don't want to create an instance of the class and If you want to access the class members from any where in the application with out creating object of it then we use static classes.
Static class does not allow user to create instances of the class as well as it restrict the user to inherit any data members/functions to derived class. So, imagine a situation where we dont want a user to create instance of class or don't want user to inherit it to child class. one should go with Static class.
if we don't need instance, and also if we do not want to inheritance.
Static Classes are used in such cases where we need some utility functions and properties. Utility functions are those functions which are very common in some software and everyone in that particular software is making use of those functions. so it does not make sense every time to create an object for such a class which is being used time to time by many programmers.
As static class is sealed, so no class can inherit a static class as well as it does not allow user to create instance of the class.So you do not need to create instance every time when you invoke its methods , As a result performance of your program will increase.
A static class does not allow us to create an instance of it using the new keyword, rather it can only contain static member and that static member is executed only once by creating a static constructor, resulting which the performance of our program will increase rather than creating multiple instances of that class.Also when we are declaring a class as static then we cannot have constructor overloading too...Hope my answer resolve your problem.
In order to provide common utilities which include functions and fields/properties.
Static Class do not required the object of a class to initialization of execution. Without creating object also the members are accessible.Safer and Faster
A static class is pure evil, creates tightly coupled code, AVOID them at all cost, unless you are an evil developer who wants to make the world a worse place.https://codeburst.io/static-classes-are-evil-or-make-your-dependencies-explicit-af3e73bd29ddhttps://blogs.msdn.microsoft.com/nickmalik/2005/09/06/are-helper-classes-evil/
Making a class static just prevents people from trying to make an instance of it. If all your class has are static members it is a good practice to make the class itself static.
1. Static class is faster 2. Only single object grantee class which will be created by compiler.Please visit for detail. https://interview-preparation-for-you.blogspot.in/2011/09/static-class.html
Static Class vs Instance Class. They are two different things that their members can be accessed with or without an instance of a class. If I need to know the possible ways from one source to another destination then there are multiple possibilities then it makes sense to have Instance Class to store all the routes. And if I am just returning the addition of two numbers then I don't need an instance to store a result. e.g Math class in. NET Framework.
we can access the object of the classes without creating instance, directly call the methods using class name. Note : If we want to declare a method as a web Method we must declare it as a static method.
It makes it obvious to users how the class is used. For instance, it would be complete nonsense to write the following code:Math m = new Math(); C# doesn’t have to forbid this but since it serves no purpose, might as well tell the user that. Certain people (including me) adhere to the philosophy that programming languages (and APIs …) should be as restrictive as possible to make them hard to use wrong: the only allowed operations are then those that are meaningful and (hopefully) correct.
Can I have one real time senario?
if we dont want to access the members from other class (non static) class then we go for static if we dont want to inherit too
if we make a class as static we don't create instance.static class have static member variable and methods only.
we can't inherit static class & static method cannot be overridden.
1.If we specify static keyword for the classes it will not allow us to create an instance of a class 2.static class and static methods will allow only only static fields and static functions ,non static are not applicable 3.all the static members will get be allocated memory as soon the class loads for the first time (Run time)
1) Static class are being used when you want to make some util methods like you want to pass some data to a method and want some processing over it and get result from there. 2) You do not need to make object for accessing its properties and methods. You use class name and dot operator and properties /Methods.
They're very easy to use, no instantiation, no disposal, just fire'n'forget. I guess this was my first unwitting attempt at creating a service oriented architecture - lots of stateless services that just did their job and nothing else.
The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object.
when we do not need to create an instance of the class then we will use static class.
Static class is used when we don't want to create instance of the class. Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object.
http://www.codeproject.com/Articles/15269/Static-Keyword-Demystified Refer this easy to understand
a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself
A static class can be used as a convenient container for sets of methods that just operate on input parameters and do not have to get or set any internal instance fields
I normally use static class when defining extension, helper or utility methods.
Making a class static just make us from trying to make an instance of it. If all your class has are static members it is to make the class itself static.
creation of instance can be restricted with static classes.
Use a static class as a unit of organization for methods not associated with particular objects. Also, a static class can make your implementation simpler and faster because you do not have to create an object in order to call its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.
A static class can make your implementation simpler and faster because you do not have to create an object in order to invoke its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.
We create static class, because we call it's method directly without create it's object.Check the following reference for more details about static class and static keyword http://www.dotnetperls.com/static:
Without creation of object you can call the method of the class in case class in static , isn'nt its great