Home > C# > Nullable type

Nullable type

Normally we are expert in using value types like int, bool, decimal types.But those types dont have null values by default. Suppouse if you want to insert null value to database for above value types.

Example:

Boolean variable can have two values: true and false. There is no value that signifies “undefined” (null). Suppose you want to insert null value in the database column for Boolean value then there is no direct option to store null value since i have only two values: true and false.

bool boolIsNull= null; // Not Possible

To handle this kind of values .NET give us a very useful tool to for this: nullable types.

Nullable<T> //Nullable<int> or Nullable<decimal>
bool? boolIsNull= null; //Correct

 

Ref: http://www.codeproject.com/Articles/275471/Nullable-Types-in-Csharp-Net


Advertisements
Categories: C#
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: