Delegate :- Delegates in C# are objects which points towards a function which matches its signature. Delegates are reference type used to encapsulate a method with a specific signature. Delegates are similar to function pointers in C++; however, delegates are type safe and secure.
Features of delegate
A delegate represents a class.
delegate is type-safe.
We can use delegates both for static and instance methods
We can combine multiple delegates into a single delegate.
Delegates are often used in event-based programming, such as
publish/subscribe.
We can use delegates in asynchronous-style programming.
We can define delegates inside or outside of classes.
Types of delegates
1) Singlecast delegates.
2) Multiplecast delegates.
Singlecast delegate : - Singlecast delegate point to single method at a time. In this the delegate is assigned to a single method at a time. They are derived from System.Delegate class.
Examples:
namespace DelegatesSample
{
public delegate int Delegateclass(int a,int b);
class Program
{
static int fun(int x, int y)
{
return x + y;
}
static void Main(string[] args)
{
Delegateclass delobj = new Delegateclass(fun);
Console.WriteLine("Create in values");
int v1 = Int32.Parse(Console.ReadLine());
int v2 = Int32.Parse(Console.ReadLine());
int res = delobj(v1,v2 );
Console.WriteLine("Results" + res);
Console.ReadLine();
}
}
}
Multicast Delegate :- When a delegate is wrapped with more than one method that is known as a multicast delegate.In C#, delegates are multicast, which means that they can point to more than one function at a time. They are derived from System.MulticastDelegate class.
Example:
namespace MuticastDelegates
{
public delegate int Calculator(int a,int b);
class MultiDelegates
{
Calculator calcul1;
Calculator calcul2;
public int Add(int x, int y)
{
return x + y;
}
public int sum(int n, int m)
{
return n - m;
}
static void Main(string[] args)
{
MultiDelegates mydel = new MultiDelegates();
mydel.calcul1 = new Calculator(mydel.Add);
mydel.calcul2 = new Calculator(mydel.sum);
mydel.calcul2 = new Calculator(mydel.Add);
int results = mydel.calcul1(12, 12);
Console.WriteLine("Results" + results);
results= mydel.calcul2(24, 12);
Console.WriteLine("Results" + results);
results = mydel.calcul2(10, 5);
Console.WriteLine("Results" + results);
Console.ReadLine();
}
}
}
Features of delegate
A delegate represents a class.
delegate is type-safe.
We can use delegates both for static and instance methods
We can combine multiple delegates into a single delegate.
Delegates are often used in event-based programming, such as
publish/subscribe.
We can use delegates in asynchronous-style programming.
We can define delegates inside or outside of classes.
Types of delegates
1) Singlecast delegates.
2) Multiplecast delegates.
Singlecast delegate : - Singlecast delegate point to single method at a time. In this the delegate is assigned to a single method at a time. They are derived from System.Delegate class.
Examples:
namespace DelegatesSample
{
public delegate int Delegateclass(int a,int b);
class Program
{
static int fun(int x, int y)
{
return x + y;
}
static void Main(string[] args)
{
Delegateclass delobj = new Delegateclass(fun);
Console.WriteLine("Create in values");
int v1 = Int32.Parse(Console.ReadLine());
int v2 = Int32.Parse(Console.ReadLine());
int res = delobj(v1,v2 );
Console.WriteLine("Results" + res);
Console.ReadLine();
}
}
}
Multicast Delegate :- When a delegate is wrapped with more than one method that is known as a multicast delegate.In C#, delegates are multicast, which means that they can point to more than one function at a time. They are derived from System.MulticastDelegate class.
Example:
namespace MuticastDelegates
{
public delegate int Calculator(int a,int b);
class MultiDelegates
{
Calculator calcul1;
Calculator calcul2;
public int Add(int x, int y)
{
return x + y;
}
public int sum(int n, int m)
{
return n - m;
}
static void Main(string[] args)
{
MultiDelegates mydel = new MultiDelegates();
mydel.calcul1 = new Calculator(mydel.Add);
mydel.calcul2 = new Calculator(mydel.sum);
mydel.calcul2 = new Calculator(mydel.Add);
int results = mydel.calcul1(12, 12);
Console.WriteLine("Results" + results);
results= mydel.calcul2(24, 12);
Console.WriteLine("Results" + results);
results = mydel.calcul2(10, 5);
Console.WriteLine("Results" + results);
Console.ReadLine();
}
}
}
http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top-69-vb-net-interview-questions-and.html
ReplyDelete
ReplyDeletethe blog is very useful, interesting and informative. thank you for sharing the blog with us. keep on updating.
Linux Training in Chennai
This is really a very great blog. the information present in this blog will be very useful for us. thank you for sharing with us.
ReplyDeleteEmail Marketing Chennai
Nice Post. with valuable info....
ReplyDeleteBest Linux Training Center in Chennai
Wanderfull post im waiting for your next postBest Ice Fishing Gloves Best Ice Fishing Gloves Best Ice Fishing Gloves
ReplyDeleteCan’t find a reliable service to order your paper from. Check our freshessays reviews on Scamfighter. Only real reviews based on personal experience and clients’ experience.
ReplyDeleteiphongthuynet
ReplyDeleteiphongthuynet
iphongthuynet
iphongthuynet
iphongthuynet
iphongthuynet
iphongthuynet
iphongthuynet
iphongthuynet
Thanks for sharing such an informative post with us.
ReplyDeleteMYOB Support
Waktu ini, kalian semua jelas sudah biasa tergugah dengan sifat dasar game ini & tentu bertanya-tanya bagaimana jalan tampil selang poker. Tapi, bagi semua orang yang target memainkan game itu
ReplyDeleteasikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
betgratis
paito warna terlengkap
syair sgp
I'm a web developer and as many developers I am an intovert. It has always been a huge problem to approach a girl and talk to her. Online dating seemed to be a solution to my problem but there are so many different sites. I read every review very carefully and found many positive reviews on charmerly. That's why I created my profile here and started chatting to pretty girls.
ReplyDeleteHyalurolift Cream
ReplyDeleteSite officiel (Magasinez maintenant) :- https://www.dietarycafe.com/hyalurolift-avis-fr/
Visitez maintenant plus d'informations:-
http://dietarycafe.mystrikingly.com/blog/hyalurolift
https://sites.google.com/site/dietarycafe/hyalurolift
https://medium.com/@dietarycafe/hyalurolift-411075288fcf
https://dietarycafe.blogspot.com/2019/12/hyalurolift.html
http://thedietarycafe.over-blog.com/hyalurolift
https://www.completefoods.co/diy/recipes/hyalurolift-avis-2
Hyalurolift Creme est un remède naturel anti-vieillissement qui inhibe la production de radicaux libres et fournit les meilleurs ingrédients pour le meilleur résultat.
You may need to experience Crypto Bitcoin. I also sent an e-mail with regard to Crypto Bitcoin.
ReplyDeleteWhere can mere mortals nab outstanding Crypto Bitcoin catalogs? If you need to know what I'm talking about, keep reading this installment.
Bitcoin Era
http://wealthcode.over-blog.com/bitcoin-era-erfahrung
https://www.facebook.com/bitcoinera.official/
Thanks for sharing this information with us...
ReplyDeletePython Training in Bangalore
Please more of these great articles. I like the way you convey ideas in a simple way that’s easy to understand. Thanks!
ReplyDeleteAWS Training in Hyderabad