[Mono-list] Constructors in C#
Brice Carpentier
brice@daknet.org
Fri, 19 Nov 2004 19:15:32 +0100
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