q-1. What is delegate.
A delegate is a class whose object (delegate object)
can store a set of references to methods. This delegate
object is used to invoke the methods
The Delegate class is the base class for delegate types. However, only the
system and compilers can derive explicitly from the Delegate class or from the
MulticastDelegate class. It is also not permissible to derive a new type from a
delegate type. The Delegate class is not considered a delegate type; it is a
class used to derive delegate types
q-2. How delegate Works internally .
whenever we declare delegate in c# initially it is
behaving as a keyword but when program gets compiled
the keyword called delegate converted into class and
compiler makes sealed class for delegate.
The sealed class implicitly inherited from multicast
delegate and multicastDelegate class implicitly inherited
from Delegate class.
multicastDelegate class and Delegate class both are marked
as a Abstract.
q-3. Why multicastDelegate class is needed?
A delegate is a class whose object (delegate object)
can store a set of references to methods means the
object of delegate class can hold the multiple method
references due to multicastDelegate.
q-4. Why Delegate class is needed?
The Delegate class plays a major role in case of
Asynchronous call back patteren.
Delegate class is carrying some major functions
like BeginInvoke() and EndInvoke() .
suppose we create a class for GUI Level like Windows Form,Web Form.
In this case we can't call a function of that class without Event.
Event can't created without delegate.There are several inbuilt
delegate class are(EventHandler,PageHandler,W ebServiceHandler).
eg
using System;
using System.Windows.Forms;
class MyWin:Form
{
Button b1;
public MyWin()
{
b1=new Button();
b1.Text="Save";
this.Controls.Add(b1);
b1.Click+=new EventHandler(save);
}
protected void save(Object o,EventArgs e1)
{
MessageBox.Show("Ready to save the record in a table");
}
public static void Main()
{
MyWin m=new MyWin();
m.ShowDialog();
}
}
// In the above program,class MyWin inherited from
Form class and Button is added to the Form.
It shows if user wants to perform any action on
the he has to click on a Button.Means without
Click he can't perform any action.
Button class is provided the Event and for Event
delegate is needed.
A delegate is a class whose object (delegate object)
can store a set of references to methods. This delegate
object is used to invoke the methods
The Delegate class is the base class for delegate types. However, only the
system and compilers can derive explicitly from the Delegate class or from the
MulticastDelegate class. It is also not permissible to derive a new type from a
delegate type. The Delegate class is not considered a delegate type; it is a
class used to derive delegate types
q-2. How delegate Works internally .
whenever we declare delegate in c# initially it is
behaving as a keyword but when program gets compiled
the keyword called delegate converted into class and
compiler makes sealed class for delegate.
The sealed class implicitly inherited from multicast
delegate and multicastDelegate class implicitly inherited
from Delegate class.
multicastDelegate class and Delegate class both are marked
as a Abstract.
q-3. Why multicastDelegate class is needed?
A delegate is a class whose object (delegate object)
can store a set of references to methods means the
object of delegate class can hold the multiple method
references due to multicastDelegate.
q-4. Why Delegate class is needed?
The Delegate class plays a major role in case of
Asynchronous call back patteren.
Delegate class is carrying some major functions
like BeginInvoke() and EndInvoke() .
suppose we create a class for GUI Level like Windows Form,Web Form.
In this case we can't call a function of that class without Event.
Event can't created without delegate.There are several inbuilt
delegate class are(EventHandler,PageHandler,W
eg
using System;
using System.Windows.Forms;
class MyWin:Form
{
Button b1;
public MyWin()
{
b1=new Button();
b1.Text="Save";
this.Controls.Add(b1);
b1.Click+=new EventHandler(save);
}
protected void save(Object o,EventArgs e1)
{
MessageBox.Show("Ready to save the record in a table");
}
public static void Main()
{
MyWin m=new MyWin();
m.ShowDialog();
}
}
// In the above program,class MyWin inherited from
Form class and Button is added to the Form.
It shows if user wants to perform any action on
the he has to click on a Button.Means without
Click he can't perform any action.
Button class is provided the Event and for Event
delegate is needed.