隐式重载,非静态 [英] Implicit overloads, non static
问题描述
我已经定义了一些隐式转换器,以便我可以这样做:
MyStruct x = 4;
将4隐式转换为MYSTRUCT。但它本质上是一个副本
构造函数,因此如果我有:
MyStruct x;
x.SomethingElse = 5;
x = 4;
现在x.SomethingElse将为0,因为x是一个新实例。好的 - 一切正常
并且已经执行 - 这里没有问题。
我想*做*是这样的。有5更新对象=不替换
它。我不寒而栗,将这与VB'旧的默认属性进行比较。但
基本上就是这样的东西。
这实际上是一个非静态的重载,据我所知,C#并不是
支持这个正确吗?还有没有办法在隐式转换器中访问当前实例
?
-
Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/
编程是一种反击的艺术形式
使用IntraWeb支持ASP.NET
http://www.atozed.com/IntraWeb/
>我愿意*做的就是这个。有5更新对象=不是
替换它。
你能详细说明吗?我不明白你的意思。
Chad Z. Hower aka Kudzu< cp ** @ hower.org>写道:我已经定义了一些隐式转换器,以便我可以做到:
MyStruct x = 4;
隐式将4转换为MyStruct 。但它本质上是一个复制
构造函数,因此如果我有:
MyStruct x;
x.SomethingElse = 5;
x = 4;
现在x.SomethingElse将为0,因为x是一个新实例。好的 - 一切正常
和执行 - 这里没有任何问题。
我愿意*做的是这样做。有5更新对象=不替换它/它。我不寒而栗,将这与VB'旧的默认属性进行比较。但是
基本上就是这样的东西。
这实际上是一个非静态的重载,据我所知,C#不支持这个正确吗?还有没有办法在隐式转换器中访问当前实例?
我不相信有什么办法可以做这个,坦率地说,我很高兴 -
以上的东西会使你的代码*非常不直观,IMO。
哎呀,即使隐含的转换也很糟糕尊重,没有
进一步滥用...
-
Jon Skeet - < sk *** @ pobox .com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
" Bruce Wood" <峰; br ******* @ canada.com>在新闻中写道:1115311764.128722.235310
@ o13g2000cwo.googlegroups.com:你能详细说明吗?我不知道你的意思。
我不确定我能说得多多 - 它非常详细。 :)
-
Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/
编程是一种反击的艺术形式
>
使用IntraWeb启动ASP.NET!
http: //www.atozed.com/IntraWeb/
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?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
> What I would *like* to do is this. Have the 5 update the object = not
replaceit.
Could you elaborate? I have no idea what you mean by this.
Chad Z. Hower aka Kudzu <cp**@hower.org> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Bruce Wood" <br*******@canada.com> wrote in news:1115311764.128722.235310
@o13g2000cwo.googlegroups.com:Could you elaborate? I have no idea what you mean by this.
Im not sure I can elaborate much more - its pretty detailed. :)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
这篇关于隐式重载,非静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!