0

If I have a method that takes in delegate as argument, is there a difference between passing in a delegate (that points to a method) and passing in the method name? If so, what are the advantage/disadvantage for each approach?

delegate void MyDel();
static void MyFunc(MyDel)
{
MyDel();
}
static void SomeFunc(){//do stuff}
static void Main()
{
MyDel del= new MyDel(SomeFunc);

//What's the difference between the approaches below?
del();
MyFunc(SomeFunc);
}
Skepti_Capy
  • 107
  • 7
  • 3
    Possible duplicate of [Are delegates and callbacks the same or similar?](https://stackoverflow.com/questions/290819/are-delegates-and-callbacks-the-same-or-similar) – GolezTrol Oct 13 '17 at 08:28
  • 2
    What is *"passing in an actual method"*? Can you give an example of both cases with code? – Sinatr Oct 13 '17 at 08:31
  • 2
    There's no such thing as "passing in an actual method" - if you use a *method group* as an argument, it's converted to a delegate. – Jon Skeet Oct 13 '17 at 08:33

1 Answers1

-3

Delegates are used to call a method threadsafe. They are typesafe and secure. Passing directly a method means that if you change e.g. a Form.Control it could crash your application. Therefor you need a delegate

Okay, I take it back :)