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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tamal MarickPosted Aug 7, 2019, 4:26 AM
Sonu GuptaPosted Aug 7, 2019, 4:06 AM
Rajanikant HawaldarPosted Aug 7, 2019, 3:57 AM
Bhuban MagarPosted Aug 7, 2019, 12:56 AM
Amit MohantyPosted Aug 7, 2019, 12:21 AM
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/