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 24, 2015, 9:34 PM EST
Thanks i enjoyed it.
Santhakumar MunuswamyPosted Oct 18, 2015, 1:02 AM EDT
Good one
Mukesh KumarPosted Oct 16, 2015, 1:48 AM EDT
Thanks Yudi
Yaduveer SainiPosted Oct 16, 2015, 1:39 AM EDT
Good One
Banketeshvar NarayanPosted Oct 15, 2015, 11:34 PM EDT
Great job.. Keep it up!
Mukesh KumarPosted Oct 15, 2015, 3:59 AM EDT
Thanks Sir
Shakti SaxenaPosted Oct 15, 2015, 3:52 AM EDT
Great
Mukesh KumarPosted Oct 9, 2015, 1:29 AM EDT
Thanks Abhishek
Mukesh KumarPosted Oct 9, 2015, 1:29 AM EDT
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, 1:26 AM EDT
Good Work sr..
Mallikarjun SadanandPosted Oct 9, 2015, 1:16 AM EDT
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 8, 2015, 9:50 PM EDT
Thanks Sujeet
Sujeet SumanPosted Oct 8, 2015, 9:15 PM EDT
Nice Article.............
Sibeesh VenuTOP 100Posted Oct 8, 2015, 9:12 PM EDT
Nice Share
Rajeesh MenothPosted Oct 8, 2015, 8:52 PM EDT
Excellent..!!
Nilesh JadavPosted Oct 8, 2015, 8:05 PM EDT
Great work !!