calling base and this constructor at same time, is possible?

  • Thread starter Thread starter murat oguzalp
  • Start date Start date
M

murat oguzalp

i want to call base and this constructor at the same time. is is possible?

i mean:
B(int a, int b, int c):base(a):this(b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}

and if yes, how is its syntax.

thanks in advance

alpos
 
Murat,

No, this is not possible. If you want to call the this and base
constructor, then you will have to call "this" constructor which in turn
calls the "base" constructor (in a chain).

In your case, you would have to have B(int, int, int) call B(int) which
in turn would call base(int).

Hope this helps.
 
Rakesh,

This is not possible, as you need to indicate whether or not you call
"this" or "base" before any code in the constructor is run.
 
murat oguzalp said:
i want to call base and this constructor at the same time. is is possible?

i mean:
B(int a, int b, int c):base(a):this(b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}

No you didn't; that is not legal java.

In Java, you'd do something like:

B(int a, int b, int c)
{
super(a);
init(b);
}

B(int b)
{
init(b);
}

private init(int b)
{
... common init logic
}

In C#, you do the same.
 
thaks to everyone for sharing information.
Mike is right. i thought, i could have done it.
but neither java, it's not legitimate
alpos
 
Back
Top