constructor

A

Alexander Widera

hi,

how can I call a constructor in a constructor?

here is my sample

public class Test
{
public int _Size = 0;
public string _Name;

Test(string name)
{
// call of constructor Test(name, 100);
}

Test(string name, int size)
{
_Name = name;
_Size = size;
// do something....
}
}


Test tvar = new Test("testman");

// tvar._Size should now be 100...



Could you help me please?

Thanks
Alex
 
H

Hans Kesting

Alexander said:
hi,

how can I call a constructor in a constructor?

here is my sample

public class Test
{
public int _Size = 0;
public string _Name;

Test(string name)
{
// call of constructor Test(name, 100);
}

Test(string name, int size)
{
_Name = name;
_Size = size;
// do something....
}
}


Test tvar = new Test("testman");

// tvar._Size should now be 100...



Could you help me please?

Thanks
Alex

Test(string name): this(name, 100)
{
}

The code in the other constructor will be called BEFORE the code
in this constructor is executed

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top