Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 131,708 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,400 people online right now. Registration is fast and FREE... Join Now!




Nullable Values in C#

 
Reply to this topicStart new topic

> Nullable Values in C#

sontek
Group Icon



post 25 Jan, 2006 - 06:01 PM
Post #1


To setup a value to be nullable you just place a question mark after its type:

CODE

int? count = null;


so now the compiler will know that you can test if that object is null (rather than setting it to a default value which can cause errors down the road).

Another cool feature in .NET 2.0 is the ?? operator, Which works a lot like the ternary operator but returns itself if the value is not null.

such as:
CODE

int? count = null;
int value = count ?? 0;


value is now 0. It would be the same as doing
CODE

int? count = null;
int value = count != null ? count : 0;



Hope this helps!
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 11/20/08 09:29AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month