What is use of static class in c#
I need to know what is use static class.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tamal MarickRank #4,584 · 336 reputationPosted Aug 7, 2019, 12:26 AM EDT
Bhuban MagarRank #1,678 · 909 reputationPosted Aug 6, 2019, 8:56 PM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Aug 6, 2019, 11:57 PM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Aug 7, 2019, 12:06 AM EDT
Amit MohantyRank #112 · 20K reputationPosted Aug 6, 2019, 8:21 PM EDT
Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.
If a class is declared as static then the variables and methods should compulsorily be declared as static
The main features of a static class are:
1. They only contain static members.
2. They cannot be instantiated.
3. They are sealed.
4. They cannot contain Instance Constructors or simply constructors as we know that they are associated with objects and operates on data when an object is created.
If you want to know When to use static class then read Mahesh Chand article When To Use Static Classes In C#.
Link: https://www.c-sharpcorner.com/article/when-to-use-static-classes-in-c-sharp/