SEARCH C# PROGRAMMING CODES HERE

Events

Events in C#
Events are client activities, like keypress event, click event, button press event and so on.
For example, Suppose you have to write the word called Apple on your computer screen, so in this case, you will press each specified alphabet key from the keyboard to get the desired output on the screen so here the activity between you and the computer which is handled by pressing specified keyboard keys is called an Event. Similarly, It can have multiple events such as click, mouseover and so on. So let's create an event program which gives notification when the user presses any key from the keyboard, So see the program below which demonstrate this.
Program
using System;

namespace Event
{
    class program
    {
        static void Main(string[] args)
        {
                        /*Info key Event*/
            ConsoleKeyInfo keyinfo;
            do
            {            /*To read key*/
                keyinfo = Console.ReadKey();
                           /*To display*/
                Console.WriteLine("---("+keyinfo.Key + ")-Key-Pressed");
            }
            while (keyinfo.Key != ConsoleKey.X);
            
        }
    }
}

     Output


















Now you can see another example which demonstrates the specified keypress event as shown below. 

Program
using System;

namespace Event
{
    class program
    {
        static void Main(string[] args)
        {
            Console.Write("Press c then enter to continue\n");

            char Key = (char)Console.Read();
        /*Creating event for the specified key 'c'*/
          
            if (Key == 'c' || Key == 'c')
            {
                                                /*Display output*/
                Console.Write("\nWellcome to the world of Rohit programming Zone");
           
            }
            else
                Console.Write("Wrong Input try again");
                Console.ReadKey();
           }
       }
}

  Output