|
-
May 29th, 2003, 04:25 PM
#1
Constructor chaining, I guess...
I remember in Java, being able to do something like this...
Code:
public class SomeClass
{
public SomeClass() { this(0); }
public SomeClass(int x) { this(x,""); }
public SomeClass(int x, string s) { /* ... */ }
}
And that would work its way down the chain of constructors so that you didn't need a lot of repeat initializing code. That may not be the completely correct syntax, but I hope you get the idea.
Anyway, this doesn't seem to work in C#. Is there any way to do something like the above in C#?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 29th, 2003, 04:32 PM
#2
PowerPoster
Try this:
Code:
public class SomeClass
{
public SomeClass(): this(0)
public SomeClass(int x): this(x, "")
public SomeClass(int x, string s) { /* ... */ }
}
-
May 29th, 2003, 04:48 PM
#3
Thanks.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|