what are delegates in c#.??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what are delegates in c#.???

19th May 2018, 12:22 AM
sidra Tabassum
sidra Tabassum - avatar
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
19th May 2018, 3:23 AM
Koketso Dithipe
Koketso Dithipe - avatar
+ 2
A delegate is a variable type that points to a method. https://code.sololearn.com/c5oXNAt6pEM3
19th May 2018, 9:19 PM
sneeze
sneeze - avatar
+ 1
thankuu so muchh
19th May 2018, 10:45 PM
sidra Tabassum
sidra Tabassum - avatar
+ 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.
22nd Aug 2020, 9:17 AM
sneeze
sneeze - avatar
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!
21st Aug 2020, 6:26 PM
CapCode
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
24th Aug 2020, 12:58 PM
CapCode