Professional Documents
Culture Documents
Implementing Static Member & Methods in C#
Implementing Static Member & Methods in C#
Static Members in C#
A C# class can contain both static and non-static members When we declare a member with the help of the keyword static, it becomes a static member A static member belongs to the class rather than to the objects of the class. Hence static members are also known as class members and non-static members are known as instance members In C#, data fields, member functions, properties and events can be declared as static
Static Field
Static fields can be declared as follows by using the class MyClass keyword static.{
public static int x; public static int y = 20; }
private static int y = 40; public static void Method() { Console.WriteLine("{0},{1}",x,y); } } class MyClient { public static void Main() { MyClass.Method(); } }