Here you go Sebastien,
public class TestConstuctor
{
public string myVarA;
public string myVarB;
public string myVarC;
public string myVarD;
public TestConstructor(string A)
{
this.myVar = A;
}
public TestConstructor(string A, string B):this(A)
{
this.myVarB = B;
}
public TestConstructor(string A, string B, string C):this(A,B)
{
this.myVarC = C;
}
public TestConstructor(string A, string B, string C, string
D):this(A,B,C)
{
this.myVarD = D;
}
}
Another way to do this is have your last constructor do all of the work:
public class TestConstuctor
{
public string myVarA;
public string myVarB;
public string myVarC;
public string myVarD;
public TestConstructor(string
A):this(A,string.Empty,string.Empty,string.Empty){}
public TestConstructor(string A, string
B):this(A,B,string.Empty,string.Empty){}
public TestConstructor(string A, string B, string
C):this(A,B,C,string.Empty){}
public TestConstructor(string A, string B, string C, string D){
this.myVarA = A;
this.myVarB = B;
this.myVarC = C;
this.myVarD = D;
}
}
hth,
Al
>From: "Sebastien Payette" <sebastien@s...>
>Reply-To: "ASPX_Professional" <aspx_professional@p...>
>To: "ASPX_Professional" <aspx_professional@p...>
>Subject: [aspx_professional] copy constructor
>Date: Wed, 30 Oct 2002 16:00:59 -0000
>
>I have a problem trying to implement a copy constructor...
>Here is what I am trying to do:
>
>public class TestConstuctor
>{
> public string myVarA;
> public string myVarB;
> public string myVarC;
>
> public TestConstructor(string A)
> {
> this.myVar = A;
> }
>
> public TestConstructor(string A, string B)
> {
> this.TestConstructor(A); //NOT GOOD!! XXXX
> this.myVarB = B;
> }
>
> public TestConstructor(string A, string B, string C)
> {
> this.TestConstructor(A,B); //NOT GOOD!! XXXX
> this.myVarC = C;
> }
>
> public TestConstructor(string A, string B, string C, string D)
> {
> this.TestConstructor(A,B,C); //NOT GOOD!! XXXX
> this.myVarD = D;
> }
>}
>
>I'm sure it is possible to achieve something like this. So far I haven't
>been able to figure out the syntax. Any ideas, suggestions?? The idea is of
>course not to have to rewrite the constructor logic every time an argument
>is added to a new constructor. Compatibility.Cheers.
>
>SEB
>
>
>---
>
>ASP.NET 1.0 Namespace Reference with C#
>http://www.wrox.com/acon11.asp?ISBN=1861007442
>
>ASP.NET 1.0 Namespace Reference with VB.NET
>http://www.wrox.com/acon11.asp?ISBN=1861007450
>
>These books are a complete reference to the ASP.NET namespaces
>for developers who are already familiar with using ASP.NET.
>There is no trivial introductory material or useless .NET
>hype and the presentation of the namespaces, in an easy-to use
>alphabetical order ensures a user-friendly reference format.
>We provide in-depth coverage of all the major ASP.NET classes,
>giving you those real-world tips that the documentation doesn't
>offer, and demonstrating complex techniques with simple
>examples.
>
>---
_________________________________________________________________
Unlimited Internet access -- and 2 months free! Try MSN.
http://resourcecenter.msn.com/access/plans/2monthsfree.asp