开发者

.NET Structs that can be assigned constant values directly like built-in types

Can you make a struct that behaves like one of the built-in classes where you can assign the value directly without calling a prope开发者_开发知识库rty?

ex:

RoundedDouble count;
count = 5;

Rather than using

RoundedDouble count;
count.Value = 5;


You do this via the implicit keyword.

For example, in your case, you'd want something like:

public static implicit operator RoundedDouble(double value)
{
     return new RoundedDouble(value);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜