Maha

Maha

  • NA
  • 600
  • 66.9k

Event with non-static

Nov 27 2015 6:18 AM

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

*/


Answers (2)