Solved

Difference between int? and int decleration ??

Posted on 2007-04-11
3
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

635 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