[Mono-list] Constructors in C#

Brice Carpentier brice@daknet.org
Sat, 20 Nov 2004 09:30:42 +0100


>> seems quite weird to me for something even vb is doing almost perfectly !
>>
> 
> MS makes use of the static From* methods throughout the runtime, so it's 
> not a completely "out there" pattern.
> 
> Also, VB actually doesn't do what you want either.  I believe you were 
> referring to the example:
> 
[exemple stripped]
Yeah, I was.

> This deceptively looks like the pattern you want, but if you try to do 
> anything before to the call to "Me.New("Tony")" you get an error saying 
> that a "Constructor call is valid only as the first statement in an 
> instance constructor."  So, this means the above is really the same as:
> 
> public Manager() : this("Tony")
> {
> 
> }
> 
> in c#.
>
oh, ok.

> The only other way i can think of is to take the code from the 
> constructor you want the other to call and put it in a separate method. 
> Then, you can have both call that method.
> 
> I can't think of any other way to eliminate code duplication otherwise.
> 
ok, then let's use a separate private method then.
Thanks

> rob
-- 
Brice Carpentier aka Br|ce