C# Program using static variables and methods


In this program, You will learn how to implement static variables and methods in C#.


static int x = 10;

static void msg(){ 
   //statement
}

Example: How to implement static variables and methods in C#.

using System;
public class Test
{
	static int x = 10;

	static void msg()
	{
		Console.WriteLine("static method is called here");
		Console.WriteLine("x value is:" + x);
	}

	public static void Main(string[] args)
	{
		msg();
	}
}

Output:

static method is called here
x value is:10