【发布时间】:2017-10-24 12:21:33
【问题描述】:
我有这个问题:
var result = (from i in dc.Sis
where i.Tid == tid && i.Sid == sid
select i);
我想使用这个索引访问一个数组:result.num,它可以为空。
string ype = YPes[result.First().num]; //if index is null then ype = null
但我收到此错误:
不能隐式转换类型“int?”到'int'。存在显式转换(您是否缺少演员表?)
【问题讨论】:
-
数组中某项的索引不能为
null -
当
result.num是null时,你想要哪个元素? -
@HenkHolterman 如果索引为空,那么我希望将空值传递给 ype 字符串
-
然后 InBetween 猜对了。