What exactly do I need delegates, and threads for?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Delegates act as the logical (but safe) equivalent to function-pointers; they allow you to talk about an operation in an abstract way. The typical example of this is events, but I’m going to use a more ‘functional programming’ example: searching in a list:
The ‘lambda’ here is essentially an instance of a delegate – a delegate of type
Predicate<Person>– i.e. ‘given a person, is something true or false’. Using delegates allows very flexible code – i.e. theList<T>.Findmethod can find all sorts of things based on the delegate that the caller passes in.In this way, they act largely like a 1-method interface – but much more succinctly.