Static Classes and Static Class Members
A static class is a class which can not be instantiated. We do not need to create an object of a static class like we did in non-static classes. Members of static classes can be accessed directly using the class name followed by a (.) and class member name. Class Members can be methods, fields, properties, or events. A static class can contain only the static members while a non-static class can contain static members. Also, Static classes are by-default sealed so they cannot be inherited.
To declare a class and its members as static, 'static' keyword are used as shown below,
- using System;
- namespace Tutpoint
- {
- // Static class
- static class TutLovers
- {
- // Static Variable
- public static int val_Static;
- // Static Method
- public static void Addition_Static()
- {
- Console.Write("Static Method");
- }
- // Static property
- public static int Addition_NonStatic
- {
- get; set;
- }
- }
For more understanding see the example shown below,
The example shown below contains two non-static classes named "TutLovers" and "TutHaters". Here a class "TutLovers" contains static as well as non-static methods and variable. When we access them from class "TutHaters" then, For the static members, they will be accessed directly using class name followed by (.) and
The example shown below contains two non-static classes named "TutLovers" and "TutHaters". Here a class "TutLovers" contains static as well as non-static methods and variable. When we access them from class "TutHaters" then, For the static members, they will be accessed directly using class name followed by (.) and
For non-static members, we have created an object of that class.

chetan patidarPosted Jan 11, 2018, 8:33 PM
why static class and satic members .. can share any real time usecase for this