In this article, I will demonstrate you all about static class with example. I will also let you know why we use the static class in place of normal class.
What is Static Class?
Static Class is a special type of class that is used to access the member functions without creating the object of the class. We can access static class members using the name of the class. The static keyword is used to create a static class. If you create a static class, all its members would be static.
Why to use static class?
If there is a requirement that we don’t need to create the instance of the class but we want to access their class members, then we create class as static.
Features of Static Class
- Static class contains only static members.
- You cannot create the instance of the static class.
- Static class can’t be inherited.
Example of Static Class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- using System.Globalization;
- namespace ConsoleApplication2
- {
- public static class Square
- {
- public static double side;
- public static double Perameter()
- {
- return side * 4;
- }
- public static double Area()
- {
- return side * side;
- }
- }
- public class Math
- {
- public static void Main()
- {
- Square.side = 20.02;
- Console.WriteLine("The side of square is " + Square.side);
- Console.WriteLine("The perameter of square is " + Square.Perameter());
- Console.WriteLine("The area of square is " + Square.Area());
- Console.ReadLine();
- }
- }
- }

Thanks for reading this article. Hope you enjoyed it.

Tony YangPosted Nov 25, 2015, 2:34 AM
Thanks i enjoyed it.
Santhakumar MunuswamyPosted Oct 18, 2015, 5:02 AM
Good one
Mukesh KumarPosted Oct 16, 2015, 5:48 AM
Thanks Yudi
Yaduveer SainiPosted Oct 16, 2015, 5:39 AM
Good One
Banketeshvar NarayanPosted Oct 16, 2015, 3:34 AM
Great job.. Keep it up!
Mukesh KumarPosted Oct 15, 2015, 7:59 AM
Thanks Sir
Shakti SaxenaPosted Oct 15, 2015, 7:52 AM
Great
Mukesh KumarPosted Oct 9, 2015, 5:29 AM
Thanks Abhishek
Mukesh KumarPosted Oct 9, 2015, 5:29 AM
Hi Sadanand... here you can see that we are using the method are field without creating the instance of the class.... It is main benefit of static class.
Abhishek KumarPosted Oct 9, 2015, 5:26 AM
Good Work sr..
Mallikarjun SadanandPosted Oct 9, 2015, 5:16 AM
Hi Mukesh Kumar... I have clearly understood what u r trying to explain... But My question is... How is it different from creating an object of the class... can u please explain?? it works the same way if u don't declare the SQUARE class as static.... Thanks in advance.. :)
Mukesh KumarPosted Oct 9, 2015, 1:50 AM
Thanks Sujeet
Sujeet SumanPosted Oct 9, 2015, 1:15 AM
Nice Article.............
Sibeesh VenuPosted Oct 9, 2015, 1:12 AM
Nice Share
Rajeesh MenothPosted Oct 9, 2015, 12:52 AM
Excellent..!!
Nilesh JadavPosted Oct 9, 2015, 12:05 AM
Great work !!