C# ?: Conditional Operator

后端 未结 8 1776
醉梦人生
醉梦人生 2020-12-05 06:26

I have this extract of C# 2.0 source code:

object valueFromDatabase;
decimal result;
valueFromDatabase = DBNull.Value;

result = (decimal)(valueFromDatabase          


        
8条回答
  •  盖世英雄少女心
    2020-12-05 07:10

    Unless I'm mistaken (which is very possible) its actually the 0 that's causing the exception, and this is down to .NET (crazily) assuming the type of a literal so you need to specify 0m rather than just 0.

    See MSDN for more info.

提交回复
热议问题