Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating a Value Type That Can be Initialized to Null
|
239
current point in the list? If so, you know the target object is at an index somewhere
in the list above the current index. If not, the object is at an index somewhere in the
list below the current index. The binary search algorithm keeps asking this question
until the object is found. In contrast, a linear search starts at the first element in a list
and determines if that object is the one you are looking for. If not, the search contin-
ues to the next element in the list. This operation keeps repeating until the object is
found in the list.
See Also
See the “LinkedList<T> Class” topic in the MSDN documentation.
4.7 Creating a Value Type That Can be Initialized
to Null
Problem
You have a variable that is a numeric type, which will hold a numeric value obtained
from a database. The database may return this value as a
null. You need a simple
clean way to store this numeric value, even if it is returned as a
null.
Solution
Use a nullable value type. There are two ways of creating a nullable value type. The
first way is to use the
? type modifier:
int? myDBInt = null;
The second way is to use the Nullable<T> generic type:
Nullable<int> myDBInt = new Nullable<int>( );
Discussion
Essentially both of the following statements are equivalent:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata