Compiler Error for Nullable Bool

前端 未结 5 1178
一向
一向 2021-01-19 07:45
 bool? ispurchased = null;
    var pospurcahsed= ispurchased ? \"1\":\"2\";

Its generating exception .

Cannot implicitly con

5条回答
  •  囚心锁ツ
    2021-01-19 08:26

    You should use .value

    bool? ispurchased = null;
    
    if (ispurchased.HasValue)
    {
        var pospurcahsed = ispurchased.Value ? "1" : "2";
    }
    

提交回复
热议问题