PC Review


Reply
Thread Tools Rate Thread

constructor call another constructor

 
 
Le, Thanh-Nhan
Guest
Posts: n/a
 
      30th Dec 2004
Hi,
How can I from constructor of a class call another constructor? As following
(as in Java):


public class Test
{

public Test()
{
this("", "");
}

public Test(String p_sErrorMessage)
{
this(p_sErrorMessage, "");
}

public Test(String p_sErrorMessage, String p_sHelp)
{
txtMessage.Text = p_sErrorMessage;
txtHelp.Text = p_sHinweis;
}

}

Thanks
Nhan


 
Reply With Quote
 
 
 
 
Moe Green
Guest
Posts: n/a
 
      30th Dec 2004

Same thing, you're just overloading the constructor.

Le, Thanh-Nhan wrote:
> Hi,
> How can I from constructor of a class call another constructor? As following
> (as in Java):
>
>
> public class Test
> {
>
> public Test()
> {
> this("", "");
> }
>
> public Test(String p_sErrorMessage)
> {
> this(p_sErrorMessage, "");
> }
>
> public Test(String p_sErrorMessage, String p_sHelp)
> {
> txtMessage.Text = p_sErrorMessage;
> txtHelp.Text = p_sHinweis;
> }
>
> }
>
> Thanks
> Nhan
>
>

 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      30th Dec 2004

"Le, Thanh-Nhan" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
> How can I from constructor of a class call another constructor? As
> following
> (as in Java):
>
>


C# uses the C++ style of contstructor invocation:

public class Test
{
public Test() :this("", "")
{
}
public Test(String p_sErrorMessage) :this(p_sErrorMessage, "")
{
}
public Test(String p_sErrorMessage, String p_sHelp)
{
txtMessage.Text = p_sErrorMessage;
txtHelp.Text = p_sHinweis;
}
}

David


 
Reply With Quote
 
Le, Thanh-Nhan
Guest
Posts: n/a
 
      31st Dec 2004
Thanks
Nhan

"David Browne" <davidbaxterbrowne no potted (E-Mail Removed)> schrieb im
Newsbeitrag news:#(E-Mail Removed)...
>
> "Le, Thanh-Nhan" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi,
> > How can I from constructor of a class call another constructor? As
> > following
> > (as in Java):
> >
> >

>
> C# uses the C++ style of contstructor invocation:
>
> public class Test
> {
> public Test() :this("", "")
> {
> }
> public Test(String p_sErrorMessage) :this(p_sErrorMessage, "")
> {
> }
> public Test(String p_sErrorMessage, String p_sHelp)
> {
> txtMessage.Text = p_sErrorMessage;
> txtHelp.Text = p_sHinweis;
> }
> }
>
> David
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get a constructor to call another constructor tshad Microsoft C# .NET 6 20th Jan 2009 01:00 AM
Constructor call constructor Geoffrey Microsoft C# .NET 7 4th Apr 2006 05:47 PM
Constructor call within a constructor Greg Microsoft C# .NET 4 9th Sep 2004 01:53 PM
can I call from one constructor another constructor ? Paul Microsoft Dot NET Framework 24 14th Jul 2004 02:29 PM
can I call from one constructor another constructor ? Paul Microsoft C# .NET 22 14th Jul 2004 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 PM.