Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# method created with this() in header
Message
De
26/03/2013 09:30:40
 
 
À
26/03/2013 09:00:34
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows XP SP2
Divers
Thread ID:
01569233
Message ID:
01569243
Vues:
41
Thanks a lot, I hope I see it. So even if I create several constructors, ":this()" makes the parametherless constructor to be called.
But when or why can it be needed?

>>If a method is created like below, how does ":this()" at the end change the result? why can it be needed at all?
>>
>> public Product(int new_id, short product_name, string product_type) : this() 
>>
>>Thanks
>
>
>The this() at the end is executing the (code of the) parameterless constructor before the code of public Product(int new_id, short product_name, string product_type)
>
>Example - execute this - you will see that Prop1 is set before Prop2
>
>	public static class qqq
>	{
>		static void Main()
>		{
>			A a = new A(23);
>			Console.ReadLine();
>		}
>	}
>
>	class A
>	{
>		int Prop1;
>		int Prop2;
>
>		public A()
>		{
>			Prop1 = 1;
>			Console.WriteLine("prop1");
>		}
>
>		public A(int x)
>			: this()
>		{
>			Prop2 = x;
>			Console.WriteLine("prop2");
>		}
>	}
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform