1.Nullable Types in C#

书目:MCTS 70-536: TS: .NET Framework 2.0-Application Development Foundation 
章节:Chapter 1: Framework Fundamentals -- Lesson 1: Using Value Types -- How to Declare Value Types
原文内容:
Declare the variable as nullable if you want to be able to determine whether a value has
not been assigned. For example, if you are storing data from a yes/no question on a
form and the user did not answer the question, you should store a null value. The following
code allows a Boolean variable to be true, false, or other:

None.gif //  C#
None.gif
Nullable < bool >  b  =   null ;
None.gif
//  Shorthand notation, only for C#
None.gif
bool ?  b  =   null ;

Declaring a variable as nullable enables the HasValue and Value members. Use Has-
Value to detect whether or not a value has been set:

None.gif //  C#
None.gif
if  (b.HasValue)Console.WriteLine( " b is {0}. " , b.Value);
None.gif
else  Console.WriteLine( " b is not set. " );

参考文章:
http://www.codeguru.com/Csharp/.NET/net_data/datagrid/article.php/c10393

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c10393__2/

转载于:https://www.cnblogs.com/jailu/archive/2007/02/14/650524.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值