草庐IT

c# - 为什么 ? : cause a conversion error while if-else does not?

coder 2023-07-07 原文

<分区>

对我使用下一行的代码进行一些更改:

uint a = b == c ? 0 : 1;

Visual Studio 向我显示此错误:

Cannot implicitly convert type 'int' to 'uint'. An explicit conversion exists (are you missing a cast?)

但是如果我使用代码:

uint a; 

if (b == c) 
    a = 0; 
else 
    a = 1;

它工作正常,没有任何错误或警告。为什么?

有关c# - 为什么 ? : cause a conversion error while if-else does not?的更多相关文章

随机推荐