A static class can be created using a keyword called
"static" used at the class definition. A static class can contain
only static members (static data members and static methods). You can‘t create
an object for the static class.
Note:
ü C#
static class contains only static members.
ü C#
static class is sealed.
ü C#
static class cannot contain instance constructors.
ü C#
static class cannot be instantiated.
Syntex:-
|
static
class StaticClassname
{
//Create static data members
//Create static methods
}
|
Example :-1
|
public
static class FileLoggerStaticClass
{
public static void Log(string
message)
{
//Method to log data .
}
}
|
The C# static class is like the normal class but it
cannot be instantiated.so a static class is basically the same as a non-static
class, but there is one difference: a static class cannot be instantiated.