我有一个关于将NULL转换为Int32的异常。
我从数据库中得到了一个可以为table的tinyint表
[Column(Storage="_StatType", DbType="tinyint NULL")]
public StatType : int { get { _StatType; } }(要获得C#代码,只需替换变量的类型)
并且在使linq选择
def StartLinq = linq <#from lpi in _CfgListParIzm
where lpi.ID_ListParIzm==drr1
select (lpi.StatType)
#> ;如果StartLinq.ToArray()[0]为空,则无法读取它:-/
mutable STT : int = 0;
try
{
_=int.TryParse(StartLinq.ToArray()[0].ToString(), out STT);
}
catch { | _ is Exception => () /* I don't care*/ }上面的代码是非常糟糕的技巧:(我不会使用它。
发布于 2010-03-23 17:44:39
我不知道nemerle,但在C#中,你会让StatType成为一个可空的整数(Nullable<int>,也就是int?),而不是一个不可空的整数。这是最合乎逻辑的解决方案-- nemerle是否支持可以为空的值类型?
https://stackoverflow.com/questions/2498797
复制相似问题