为什么不是这个C#code编译? [英] Why doesn't this C# code compile?
本文介绍了为什么不是这个C#code编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
翻番?测试=真的吗?空:1.0;
在我的书,这是一样的
如果(真){
测试= NULL;
} 其他 {
测试= 1.0;
}
不过,第一行给这个编译器错误:
有条件的前pression类型不能 来确定,因为没有 之间';零>
&LT'隐式转换 和
双
。
解决方案
翻番?测试=真的吗?空(双?)1.0;
double? test = true ? null : 1.0;
In my book, this is the same as
if (true) {
test = null;
} else {
test = 1.0;
}
But the first line gives this compiler error:
Type of conditional expression cannot be determined because there is no implicit conversion between '
<null>
' and 'double
'.
解决方案
double? test = true ? null : (double?) 1.0;
这篇关于为什么不是这个C#code编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文