36
Reply

Why we use static class?

Ujjval Shukla

Ujjval Shukla

Jan 29, 2016
19k
2

    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.

    Pankaj Kumar Choudhary
    February 09, 2016
    7

    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# .

    Ammar Shaukat
    July 18, 2017
    3

    to access a particular class from anywhere inside the solution and no need to create object to access it just use it directly.

    Mohammed Deeb Hammoudeh
    December 15, 2016
    3

    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.

    kiran kumar
    October 07, 2016
    3

    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.

    Anil Kumar Murmu
    February 02, 2016
    3

    if we don't need instance, and also if we do not want to inheritance.

    Naveen Bisht
    June 22, 2016
    2

    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.

    Abhishek Panigrahi
    September 06, 2017
    1

    In order to provide common utilities which include functions and fields/properties.

    Vineet Kumar
    January 13, 2017
    1

    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.

    Bharathi Raja
    January 20, 2018
    0

    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# .

    Ammar Shaukat
    July 18, 2017
    0

    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

    Khaleek Ahmad
    February 03, 2017
    0

    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.

    Kshamesh Atnoorkar
    January 05, 2017
    0

    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.

    Manoj Kumar
    December 30, 2016
    0

    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.

    Subhashkumar Yadav
    December 19, 2016
    0

    to access a particular class from anywhere inside the solution and no need to create object to access it just use it directly.

    Mohammed Deeb Hammoudeh
    December 15, 2016
    0

    Can I have one real time senario?

    Sailaja Tummuru
    December 12, 2016
    0

    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

    Khaja Moizuddin
    December 02, 2016
    0

    if we make a class as static we don't create instance.static class have static member variable and methods only.

    Ananth G
    October 21, 2016
    0

    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)

    Hari Shanker
    July 11, 2016
    0

    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.

    Deeksha Pandit
    July 04, 2016
    0

    if we don't need instance, and also if we do not want to inheritance.

    Naveen Bisht
    June 22, 2016
    0

    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.

    Vasanth Natarajan
    June 10, 2016
    0

    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.

    Keerthi Venkatesan
    June 08, 2016
    0

    when we do not need to create an instance of the class then we will use static class.

    Avikshith Aradhya
    June 06, 2016
    0

    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.

    Avikshith Aradhya
    May 30, 2016
    0

    http://www.codeproject.com/Articles/15269/Static-Keyword-Demystified Refer this easy to understand

    Thiruppathi R
    May 25, 2016
    0

    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

    Rubiya Rajamanickam
    April 29, 2016
    0

    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

    Barkha Gupta
    April 12, 2016
    0

    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.

    Keerthi Venkatesan
    April 11, 2016
    0

    creation of instance can be restricted with static classes.

    Srikanth Reddy
    March 15, 2016
    0

    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.

    Surya Pratap Singh
    March 06, 2016
    0

    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.

    Munesh Sharma
    February 09, 2016
    0

    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:

    Vivek Kumar
    February 07, 2016
    0

    Without creation of object you can call the method of the class in case class in static , isn'nt its great

    Nishant Mittal
    February 01, 2016
    0