for questions like this, it's a good idea to use Google "c# reasons to use delegates".
You will find there is a lot of material ... after reading through the material, you will be better equipped to ask your questions, plus you will already have answered some of these questions yourself.
one example is the use of delegates in custom comparison, for example, see http://msdn.microsoft.com/en-us/library/w56d4y5z(v=vs.110).aspx "List<T>.Sort
Method (Comparison<T>)". ==> "If comparison is provided, the elements of the List<T> are
sorted using the method represented by the delegate." ~~ imagine you wanted a method where you wanted to place items of a list in a specific, non-alphabetic ordering, for example, vowels first, followed by consonants, with small consonants c, m, n,
... followed by full height consonants b, d, f, ... followed by consonants with descenders g, j, p, ... ....
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
I have gone through different articles to get at idea about what is delegate, and it usage...., Some one pointed out delegate can be used as an example for a calculator class where each of mathematical functions accepts same number of parameters and
have same return type and using delegate we can call any of the function by passing the function name indicator and fetch a particular function, which I feel can be done by normal function and calling based on different condition.
or many of the articles goes on to explaining event implementation as delegates usage.
May be a clear real world example of delegate will make it more understandable. o.w even after going through many application I will not be able to apply delegate when required and go-on some other way which may be time consuming.
What I am looking at is a real world example where delegate are used and alternative to implement the same and how delegate has edge over other implementation.
in the example that i gave where one wants a unique way of putting data in an special order ("List<T>.Sort Method (Comparison<T>)"),
a delegate must be used because the designer(s) of List<T>.Sort chose to allow you to use a delegate.
an entirely different approach would need to be taken for List<T>.VickySanSort, for example, you might have your VickySanSort take a parameter List<String> where the consumer of VickySanSort must present a List<String>
of rules, using a syntax that you specified to specify rules similar to my example at http://forums.asp.net/post/5795277.aspx above.
VickySan
What I am looking at is a real world example where delegate are used and alternative to implement the same and how delegate has edge over other implementation.
also, in the idea that i've just presented above, the delegate in the existing .NET Framework method allows the consumer programmer to create her/his own method without having to learn your rules in the hypothetical VickySanSort rules method; additionally,
the existing .NET Framework method therefore allows the consumer programmer to create her/his own method to cover cases for which your VickySanSort rules might be inadequate.
imho, it's fair to claim that delegates are simply far more powerful solutions when great flexibility is highly desirable.
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
Member
21 Points
16 Posts
delegates and events
Oct 18, 2014 08:31 PM|VickySan|LINK
1. what makes delegates favourite choice for event implementations.
2. is there an alternative way for implementing event i.e; without using delegates.
3. just wanted to see some examples where delegates being the best fit, other than being used for events.
Star
14297 Points
5797 Posts
Re: delegates and events
Oct 19, 2014 12:05 AM|gerrylowry|LINK
@VickySan i recommend that you study the following articles; if c# is your only language, the idea of delegates may be totally new to you.
http://msdn.i microsoft.com/en-us/library/ms173172.aspx "Using Delegates (C# Programming Guide)"
for questions like this, it's a good idea to use Google "c# reasons to use delegates".
You will find there is a lot of material ... after reading through the material, you will be better equipped to ask your questions, plus you will already have answered some of these questions yourself.
one example is the use of delegates in custom comparison, for example, see http://msdn.microsoft.com/en-us/library/w56d4y5z(v=vs.110).aspx "List<T>.Sort Method (Comparison<T>)". ==> "If comparison is provided, the elements of the List<T> are sorted using the method represented by the delegate." ~~ imagine you wanted a method where you wanted to place items of a list in a specific, non-alphabetic ordering, for example, vowels first, followed by consonants, with small consonants c, m, n, ... followed by full height consonants b, d, f, ... followed by consonants with descenders g, j, p, ... ....
Member
670 Points
281 Posts
Re: delegates and events
Oct 21, 2014 05:07 PM|sen338|LINK
The below site may help you out
http://msdn.microsoft.com/en-us/library/orm-9780596516109-03-09.aspx
Member
21 Points
16 Posts
Re: delegates and events
Oct 22, 2014 04:42 AM|VickySan|LINK
Hi Gerry,
Thanks for your reply
I have gone through different articles to get at idea about what is delegate, and it usage...., Some one pointed out delegate can be used as an example for a calculator class where each of mathematical functions accepts same number of parameters and have same return type and using delegate we can call any of the function by passing the function name indicator and fetch a particular function, which I feel can be done by normal function and calling based on different condition.
or many of the articles goes on to explaining event implementation as delegates usage.
May be a clear real world example of delegate will make it more understandable. o.w even after going through many application I will not be able to apply delegate when required and go-on some other way which may be time consuming.
What I am looking at is a real world example where delegate are used and alternative to implement the same and how delegate has edge over other implementation.
Star
14297 Points
5797 Posts
Re: delegates and events
Oct 22, 2014 10:38 AM|gerrylowry|LINK
@VickySan
in the example that i gave where one wants a unique way of putting data in an special order ("List<T>.Sort Method (Comparison<T>)"), a delegate must be used because the designer(s) of List<T>.Sort chose to allow you to use a delegate.
an entirely different approach would need to be taken for List<T>.VickySanSort, for example, you might have your VickySanSort take a parameter List<String> where the consumer of VickySanSort must present a List<String> of rules, using a syntax that you specified to specify rules similar to my example at http://forums.asp.net/post/5795277.aspx above.
also, in the idea that i've just presented above, the delegate in the existing .NET Framework method allows the consumer programmer to create her/his own method without having to learn your rules in the hypothetical VickySanSort rules method; additionally, the existing .NET Framework method therefore allows the consumer programmer to create her/his own method to cover cases for which your VickySanSort rules might be inadequate.
imho, it's fair to claim that delegates are simply far more powerful solutions when great flexibility is highly desirable.