可空类型 int? , bool? DateTime? 数据库的值为空 DBNull.Value

int?  i

表示可空类型,有什么意义呢?

public static int? GetAge()

{

return null;

}

 

int? i=GetAge();

 

只要在类型后面加了 ? ,那么就表示这个类型 可以为空。一般有 int?  ,  bool?   DateTime?  这3个类型.

而string name=null; person p1=null  这样是可以的,因为是引用类型,可以为null

 

另外,当我们不能确定数据库的值是不是为空的时候,我们用 row["createdate"] != DBNull.Value 来判断,或者是用  row.IsNull("createdate")来判断是不是为空

posted @ 2012-08-27 16:02  asp_net老友记  阅读(311)  评论(0编辑  收藏  举报