书目: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:
//
C#
Nullable < bool > b = null ;
// Shorthand notation, only for C#
bool ? b = null ;
Nullable < bool > b = null ;
// Shorthand notation, only for C#
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:
//
C#
if (b.HasValue)Console.WriteLine( " b is {0}. " , b.Value);
else Console.WriteLine( " b is not set. " );
if (b.HasValue)Console.WriteLine( " b is {0}. " , b.Value);
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/