This program is compiling well.
If we remove static key word, what should be done to compile again. Question is highlighted.
using System;
public delegate void EventHandler();
class Program
{
public static event EventHandler _show;
static void Main()
{
// Add event handlers to Show event.
_show += new EventHandler(Dog);
_show += new EventHandler(Cat);
_show += new EventHandler(Mouse);
_show += new EventHandler(Mouse);
// Invoke the event.
_show.Invoke();
Console.ReadKey();
}
static void Cat()
{
Console.WriteLine("Cat");
}
static void Dog()
{
Console.WriteLine("Dog");
}
static void Mouse()
{
Console.WriteLine("Mouse");
}
}
/*
Dog
Cat
Mouse
Mouse
*/

MahaPosted Nov 30, 2015, 3:26 AM
Raja TPosted Nov 30, 2015, 1:15 AM
Finally i understand the static variable.....static variable shared the value of it among all instances of the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static int a; // initialized at the time of declaration
public static int Hello()
{
a = 20;
return a;
}
}
class run
{
static void Main(string[] args)
{
//Program p = new Program();
Console.WriteLine(Program.Hello());
}
}
}
Output
20