>>Is there any difference between defining a delegate inside a class as opposed to outside it? If so, what?
>
>When you declare a delegate you're actually creating a class (System.MulticastDelegate) so doing so inside a class is the equivalent of creating a nested class. Couple of considerations (there may be others):
>If the delegate is associated with a particular class then declaring it within the class may provide more intuitive syntax.
>OTOH if you place it inside a large class you have to instantiate the containing class just to use the delegate.......
Viv,
>OTOH if you place it inside a large class you have to instantiate the containing class just to use the delegate.......
Do you mean that, if a delegate is declared inside a class, you have to instantiate that class, just to use the delegate ?
If yes, I don't think so
I think a declaration of a delegate is just a declaration
class test2
{
static void Main()
{
AClass.TheDelegate func = PrintOne;
func("hello");
Console.ReadLine();
}
static void PrintOne( string s )
{
Console.WriteLine(s);
}
}
public class AClass
{
public delegate void TheDelegate( string s );
}
Gregory