.net2.0中新增的nullable类型
来源:互联网 发布:cs架构b2b源码 编辑:程序博客网 时间:2024/05/21 08:43
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
.net 2.0中,有新增的nullable类型,主要可以用为基本的值类型赋予null的值,比如
int? k = 3;//一个可为空的值类型(简称空类型)
int m = null;//错误
int? j = null;//成功
从上面的例子我们可以看到在值类型后可以定义一个可为空的值类型,在C#中,是在基本类型后加一个?号,而在VB.net中,可以这样
Dim dtmVarName As nullable(Of DateTime)
Dim intVarName As nullable(Of Integer)
Dim bVarName As nullable(Of Boolean)
要注意的是,空类型不是一种新的.net数据类型。
实际上空类型是定义在.net库中的一种范型类System.nullable<T>,其中T就是可替换的值类型。
int? k = 3;同样可以写作System.nullable<int> k = 3;
其中的操作是通过该类的运算符重载实现的
可以用hasvalue来判断空类型中是否已经有赋值了
if (dtmVarName.HasValue)
{
//...do something
}
http://www.cnblogs.com/jackyrong/archive/2006/08/26/486796.html
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- .net2.0中新增的nullable类型
- .net2.0中新增的nullable类型
- .net 2.0中新增的nullable类型
- .net 2.0中新增的nullable类型
- .net 2.0中新增的nullable类型
- .net 2.0中新增的nullable类型_asp.net使用技巧
- ASP.NET2.0新增
- nullable类型
- Nullable类型
- Nullable类型
- Nullable类型
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- 可空类型的转换问题(?|nullable)
- 可空类型的判断 System.Nullable
- C# Nullable的类型转换问题
- 小tips:asp.net2.0中在gridview中使用DataFromatString
- ASP.NET2.0Membership
- .net后台的小偷程序
- 应用lucene.net进行搜索测试
- 在VisualStudio2005和ASP.NET2.0中使用强类型数据存取
- .net2.0中新增的nullable类型
- 收藏一段小的.net下的验证码片段
- asp.net2.0小TIPS两则
- 支持正则表达式的UrlMapping(ASP.NET2.0)
- ASP.NET中为DataGrid添加单选框
- .Net下几种日志管理方法
- ASP.NET2.0登陆控件的使用(常见的三种方法)
- ASP.NET2.0X64的奇怪问题
- ASP.NET2.0-EnterKey-DefaultSubmitButton