Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Delegate Question
Message
From
22/10/2009 05:27:08
 
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01430525
Message ID:
01430570
Views:
39
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform