Re: Implicit overloads, non static



Chad Z. Hower aka Kudzu <cpub@xxxxxxxxx> wrote:
> I have defined some implicit convertors so that I can do:
>
> MyStruct x = 4;
>
> The implicit convert the 4 into MyStruct. But its essentially a copy
> constructor and thus if I had:
>
> MyStruct x;
> x.SomethingElse = 5;
> x = 4;
>
> Now x.SomethingElse will be 0, because x is a new instance. Ok - all proper
> and as exected - no questions here.
>
> What I would *like* to do is this. Have the 5 update the object = not replace
> it. I shudder to compare this to VB's old "default properties" but
> essentially soemething like that.
>
> This is really a non static overload, and as I understand it, C# does not
> support this correct? And also there is no way to access the current instance
> in the implicit convertors?

I don't believe there's any way to do this, and frankly I'm glad -
things like the above would make your code *very* unintuitive, IMO.
Heck, even implicit conversions are bad enough in that respect, without
further abuse...

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.