Compiler Error for Nullable Bool

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

Its generating exception .

Cannot implicitly con

5条回答
  •  梦谈多话
    2021-01-19 08:29

    You can't use Nullable or bool? in condition directly, instead use it like:

    var pospurcahsed= (ispurchased.HasValue && ispurchased.Value) ? "1":"2";
    

提交回复
热议问题