[Mono-list] Constructors in C#
Joe Audette
joe_audette@yahoo.com
Fri, 19 Nov 2004 10:51:12 -0800 (PST)
--0-1287129030-1100890272=:35829
Content-Type: text/plain; charset=us-ascii
The java example should work as is in C#
Brice Carpentier <brice@daknet.org> wrote:Hi folks,
I think I'm gonna ask a dumb question, but well, I've been crawling the
web for about an hour or so and didn't find the answer, so let's ask :
Basically what I want is what can be done in Java the following way :
public class MyClass
{
private String member;
public MyClass ()
{
this("stuff");
}
public MyClass (String s)
{
this.member = s;
}
}
or in vb this way (according to http://tinyurl.com/3lcyy) :
Public Class Manager
Private nameField As String
Public Sub New()
'give nameField a default value
nameField = "Tony"
System.Console.WriteLine("I am the manager.")
End Sub
Public Sub New(ByVal name As String)
nameField = name
System.Console.WriteLine("I am the manager.")
End Sub
End Class
I noticed I could do something like :
public class MyClass
{
private string member;
public MyClass () : this("stuff") {}
public MyClass (string s)
{
this.member = s;
}
}
but I've got some checks to do before calling the second constructor and
therefore cannot use that method.
Any hint ?
Regards,
--
Brice Carpentier aka Br|ce
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
joe_audette@yahoo.com
http://www.joeaudette.com
http://www.mojoportal.com
--0-1287129030-1100890272=:35829
Content-Type: text/html; charset=us-ascii
<DIV>The java example should work as is in C#<BR><BR><B><I>Brice Carpentier <brice@daknet.org></I></B> wrote:
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Hi folks,<BR>I think I'm gonna ask a dumb question, but well, I've been crawling the <BR>web for about an hour or so and didn't find the answer, so let's ask :<BR><BR>Basically what I want is what can be done in Java the following way :<BR><BR>public class MyClass<BR>{<BR>private String member;<BR><BR>public MyClass ()<BR>{<BR>this("stuff");<BR>}<BR><BR>public MyClass (String s)<BR>{<BR>this.member = s;<BR>}<BR>}<BR><BR>or in vb this way (according to http://tinyurl.com/3lcyy) :<BR><BR>Public Class Manager<BR>Private nameField As String<BR><BR>Public Sub New()<BR>'give nameField a default value<BR>nameField = "Tony"<BR>System.Console.WriteLine("I am the manager.")<BR>End Sub<BR><BR>Public Sub New(ByVal name As String)<BR>nameField = name<BR>System.Console.WriteLine("I am the manager.")<BR>End Sub<BR>End Class<BR><BR>I noticed I could do something like :<BR><BR>public class
MyClass<BR>{<BR>private string member;<BR><BR>public MyClass () : this("stuff") {}<BR><BR>public MyClass (string s)<BR>{<BR>this.member = s;<BR>}<BR>}<BR><BR>but I've got some checks to do before calling the second constructor and <BR>therefore cannot use that method.<BR>Any hint ?<BR><BR>Regards,<BR><BR>-- <BR>Brice Carpentier aka Br|ce<BR>_______________________________________________<BR>Mono-list maillist - Mono-list@lists.ximian.com<BR>http://lists.ximian.com/mailman/listinfo/mono-list<BR></BLOCKQUOTE></DIV><BR><BR>joe_audette@yahoo.com<br>http://www.joeaudette.com<br>http://www.mojoportal.com
--0-1287129030-1100890272=:35829--