Solved

Difference between int? and int decleration ??

Posted on 2007-04-11
3
246 Views
Last Modified: 2010-04-15
Please explain the difference between:

int i;
and
int? i;

Best regards,
Kaj Bromose
0
Comment
Question by:bromose
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Thalox earned 125 total points
ID: 18888566
? after a type means it can be null.
if you assign null "normal" variable (e.g from a database) this will throw an exception. a nullable type will not.

for more info have a look at

http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx

Thalox
0
 
LVL 16

Assisted Solution

by:AlexNek
AlexNek earned 125 total points
ID: 18888581
"A nullable type can represent the normal range of values for its underlying value type, plus an additional null value"
http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx

Nullable value types (denoted by a question mark, ie int? i = null;) which add null to the set of allowed values for any value type. This provides improved interaction with SQL databases, which can have nullable columns of types corresponding to C# primitive types: an SQL INTEGER NULL column type directly translates to the C# int?.

http://en.wikipedia.org/wiki/Nullable_Types
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18888584
You type more quickly. :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now