Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# method created with this() in header
Message
From
26/03/2013 09:30:40
 
 
To
26/03/2013 09:00:34
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01569233
Message ID:
01569243
Views:
42
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");
>		}
>	}
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform