What is a delegate?

Answer Posted / sadab alam

Delegate is refrence type varible that holds the refrence
to a method.
There are two type of delegte
1.Sigle cast delegate
2.Multi cast delegate
if delgate variable contains refrence of one method then it
is called sinlecast delegate
and if contains refrence of more than one method then it is
called multicast refrence.

using System;
public delegate void mydel();
class del
{
public static void method1()
{
Console.WriteLine("first method");
}
public static void method2()
{
Console.WriteLine("Second method");

}
public static void Main()
{
mydel d=new mydel(method1);
d+=new mydel(method2);
d();
}
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between private and protected in c#?

484


Which compiler switch creates an xml file from xml comments in the files in an assembly?

572


What is parameter c#?

526


Explain how do you convert a value-type to a reference-type?

442


What are types of constructor?

464






What is an interface class? Give one example of it

472


What is the difference between method parameters and method arguments. Give an example?

502


What is difference between hashtable and dictionary in c#?

485


Can you inherit multiple abstract classes in c#?

479


Is unboxing an implicit conversion?

526


Why we use delegates in c#?

489


Why delegates are required?

528


Is predicate a functional interface?

476


What do you mean by “finalize” and “finally” methods in c#?

476


What is the difference between struct and class c#?

469