R
Roger Webb
Hey All,
I looked through the news group and found a few threads on inheriting
constructors...which I dont think is what I want to do here... since I'm
dealing with issues between constructors of the same class.
Basically I would like to know how to call one constructor from another one.
I know that you can do something like A():this(10) to default a value,
however, I want to do a little more... something like
public class Class1
{
private int A;
public Class1(int x)
{
A = x;
}
public Class1(string x)
{
this(x.ToString());
}
public Class1(bool x)
{
if(x)
{ this(1);}
else
{ this(0);}
}
}
however, this gives a "Method Name Expected" Error on compile. I realize
this is a simple constructor... but is there a way I dont have to duplicate
the code that would go along with the Class1(int x) constructor in each
constructor?
- Roger Webb
I looked through the news group and found a few threads on inheriting
constructors...which I dont think is what I want to do here... since I'm
dealing with issues between constructors of the same class.
Basically I would like to know how to call one constructor from another one.
I know that you can do something like A():this(10) to default a value,
however, I want to do a little more... something like
public class Class1
{
private int A;
public Class1(int x)
{
A = x;
}
public Class1(string x)
{
this(x.ToString());
}
public Class1(bool x)
{
if(x)
{ this(1);}
else
{ this(0);}
}
}
however, this gives a "Method Name Expected" Error on compile. I realize
this is a simple constructor... but is there a way I dont have to duplicate
the code that would go along with the Class1(int x) constructor in each
constructor?
- Roger Webb