By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,942 Members | 1,922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,942 IT Pros & Developers. It's quick & easy.

Why use delegates?

P: 93
Why use delegates?

I understand HOW to use delegates, but in what situations would you actually use them? The examples I see in the literature are all in situations where the code could just be written without ever using them.
Feb 26 '09 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 750
Check this and MSDN...
Feb 27 '09 #2

Expert 100+
P: 229
If you can get the desired result through a static method, you have to use a delegate, because you cannot use interfaces with static methods. Delegate is represented only by a single method signature, and it doesn't care if that method is static or instance (a nice thing is also passing anonymous delegates, or Lambda expressions in C# 3.0).

On the other hand, interfaces allow you to pass an object with some encapsulated state information, which you cannot do with static methods (ok, I guess you can have static properties also, but you get the point). Interfaces also contain multiple method and property signatures, when compared to a single delegate.
Feb 27 '09 #3

P: 26
In C# Console Application if u want to fire event then
u have to compulsory declare delegate bcoz delegate
is a base of any event & without delegate event is not
possible in C# console application.

I Hope your doubt is clarify...
Feb 27 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.