HTML clipboard
C# provides the important feature to create static classes, there are two main features of a static class, one is no object of static class can be created and another is, a static class must contain only static members, then it is important that what is the main benefit to create a static class, the main benefit of making static class, we do not need to make any instance of this class ,all members can be accessible with its own name.
Declaration
A static class is created by using keyword 'Static' as shown here:
- Static class Clasname
- {
- //C#
- }
One more thing that is notable-within static class, all members must be explicitly specified as static, static class does not automatically make its members static. Static class can contain a collection of static methods.
Example
- using System;
- static class Shape {
- public static double GetArea(double Width, double height) {
- return Width * Height;
- }
- }
- class Ractangle {
- private void GetRactangleArea() {
- Double Area;
- Area = Shape.GetArea(10, 5);
- }
- }
Shape is static class, it contain staic function GetArea.Ractangle is other class and with in GetArea function can be access without creating instace of Class Shape.
Although a static class cannot have an instance constructor, it can have a static constructor.


Yogesh WaniPosted Sep 12, 2017, 9:35 PM EDT
One more thing you can add Static Class does not have constructors like other class.
SubashPosted Nov 17, 2016, 6:24 AM EST
Very simple explanation easy to understand
Former memberPosted Nov 20, 2015, 9:07 PM EST
What is a feature of static classes? a) They may have sealed or abstract modifiers.b) They may inherit from another class or be inherited.c) They may contain instance members.d) They may have members with protected or protected internal accessibility.e) They may be marked as partial. PLZ RPLY FOR THIS
Shobhit KaushikPosted Oct 29, 2015, 9:20 AM EDT
very good
Muralitharan APosted Jun 21, 2015, 10:17 PM EDT
Thank you... very clear and easy to understand sample..
wasim adddPosted May 5, 2015, 11:41 PM EDT
when we don't require to store any data for objects, we can use static class, System.Math is static class
Ranjit kumarPosted Mar 5, 2013, 8:09 PM EST
USUFULL
santi mahapatraPosted Jun 20, 2012, 1:48 AM EDT
very good explained
John BurnsPosted Dec 16, 2010, 9:55 PM EST
Very helpful for me, thanks