Sorry if this question is too simple or easy.
I just started studying Delegates using C#. When I tried to declare one inside a function I got design time errors, but when I declare the same Delegate at class level, it works fine. Why?
If matters this is the code: delegate void Test();
AFAIK, declaring a delegate like that (in C#, which I assume is the language you are using) is declaring a new type. Just as you cannot declare classes, structs, or interfaces in a method, you cannot declare this type.
Edit: If you're just learning delegates, and the language is indeed c#, consider using the Func templated delegate! It will save you from having declarations everywhere.
http://msdn.microsoft.com/en-us/library/bb549151.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With