【发布时间】:2010-03-23 09:40:45
【问题描述】:
我有关于将 NULL 转换为 Int32 的异常。
我从数据库中获得了一个可以为空的 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] 为 null 时无法读取:-/
mutable STT : int = 0;
try
{
_=int.TryParse(StartLinq.ToArray()[0].ToString(), out STT);
}
catch { | _ is Exception => () /* I don't care*/ }
上面的代码是非常糟糕的技巧:(我不会使用它。
【问题讨论】:
-
为什么这个问题被标记为 C#?
-
问题是关于可以为空的整数。我不希望得到 Nemerle 的回答。但也许我做错了:-/
-
@Peter - 它有点像 C#。它还与 nemerle 混合在一起nemerle.org
-
Nullable 类型不是 C# 特定的,它是 .Net Framework 的一个特性。哦,看来@nCdy 做对了……
标签: c# .net linq-to-sql nemerle