+ 2
what are delegates in c#.???
6 Answers
+ 9
A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.
For more info:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/
I hope this helps
+ 2
A delegate is a variable type that points to a method.
https://code.sololearn.com/c5oXNAt6pEM3
+ 1
thankuu so muchh
+ 1
Delegate area a variable type. So if you work with 2 classes is similair to methods and properties.
If they need to be shared, you can make them public or private.
https://code.sololearn.com/cv89vWInRR06
Since they are a type, they are not bound to a instance but you can reference them via the class-reference.
0
sneeze How would it work with 2 classes?
I mean, consider you need access to the method of "class A" from "class B", without a reference between those classes?
Anyway, a good example!
0
sneeze Thanks for the explanation!
I still got a question tho..
What is the benefit of using delegates in your second example, when I already have a reference to "class B"? I mean I could directly call those specific methods of " class B" instead of letting the delegate of "class A" point to them.
Thanks