C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Nullable Types


Posted Date: 04 Jun 2008    Resource Type: Definitions    Category: General

Posted By: shakti singh tanwar       Member Level: Diamond
Rating:     Points: 5



Types that are value types but can hold a null value also apart from the normal range of integer values e.g. Nullable, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A Nullable can be assigned the values true or false, or null.

Nullable types are instances of the System.Nullable struct.

Declaration:-
int? i
or
Nullable i;

Examples:-
In example below HasValue returns true if object is not null.
int? num = null;
if (num.HasValue == true)
{
System.Console.WriteLine("num = " + num.Value);
}
else
{
System.Console.WriteLine("num = Null");
}


To give default value or null use
int y = num.GetValueOrDefault();


Besides this the Value property returns a value if one is assigned, otherwise a System.InvalidOperationException is thrown

Prior to .Net 2.0 there was a huge gap between database types and c# types e.g. for an int value we can have null in database but in c# int or we can say value types couldn't hold null values..Net 2.0 was the first step towards bridging this gap and it did by introducing nullable types i.e.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ActiveX Control Importer tool -- Aximp.exe
Previous Resource: Lambda expression
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use