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:00:34
 
 
To
26/03/2013 08:39:41
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:
01569240
Views:
59
This message has been marked as the solution to the initial question of the thread.
>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");
		}
	}
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform