Static Class
* Only 1 instance of the object is created for static classes
* Static class Should be declare static keyword for declare constructor or method or variable
* Can't specify access specifier for static Constructor
* Static constructor should run only once.
Example
public static class MyClass
{
static MyClass()
{
Console.WriteLine("Static Constructor");
}
public static void SomeMethod()
{
Console.WriteLine("Some Methods");
}
}
static void
Main(string[] args)
{
MyClass.SomeMethod();
MyClass.SomeMethod();
}
O/P
Static Constructor
Some Methods
Some Methods
This comment has been removed by the author.
ReplyDelete