Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delegate Question
Message
De
22/10/2009 05:27:08
 
 
À
22/10/2009 04:44:40
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01430525
Message ID:
01430570
Vues:
37
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform