Interview answers verified by specialists.

Find interview questions and answers on this website:


See right interview answers on 30 common job interview questions

Describe Event in .Net.

Ans.It is an important feature of C# that is based upon delegate. An Event is a message sent by an object such as control (Button, Checkbox, Radio button,etc.) or other part of the user interface, that the program responds to by executing code. It is an automatic notification that some action has occurred.
Events are members of a class and are declared using the eventkeyword. The general prototype of an event declaration 

event event-delegate event-name;

  Example:

using System;
namespace Test
{
// Declare a delegate type for an event.
delegate void MyEventHandler();
// Declare a class that contains an event.
class MyEvent
{
public event MyEventHandler SomeEvent;
// This is called to fire the event.
public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
}
class EventDemo
{
// An event handler.
static void MyHandler()
{
Console.WriteLine("Event occurred");
}
static void Main()
{
MyEvent evt = new MyEvent();
// Add MyHandler() to the event list.
evt.SomeEvent += MyHandler;
// Fire the event.
evt.OnSomeEvent();
}
}
}

Do you know that?

Clients search Elance for online hires over 6.1M times each year. That's 696 times per hour Next

Articles:

Popular:

Fast Payments
Payoneer sing up to get free 
$25