开发者

double? to decimal? conversion

Why after this code fragment:

 double? d = 123.4;
 decimal? dec = (decimal?)d; //dec is null

is dec's v开发者_StackOverflow中文版alue null?


I've tested on .NET 2.0 and .NET 4.0, and I get dec as 123.4, as expected. Are you sure you don't perhaps have the break-point too high?


dec isn't null, its 123.4


I know this will point same thing. Your code gives me 123,4 as expected. It works fine.

I can just say try this :) but the result is same : 123,4

double? d = 123.4;
 decimal? dec = (decimal?)d.Value;


My best guess is that the implicit conversion being called in the cast fails, leaving dec with a null value, rather than whatever truncated/rounded value you expect.


It's not null. You must have an error elsewhere.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜