Difference between int? and int decleration ??

Posted on 2007-04-11
Medium Priority
Last Modified: 2010-04-15
Please explain the difference between:

int i;
int? i;

Best regards,
Kaj Bromose
Question by:bromose
  • 2

Accepted Solution

Thalox earned 500 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


LVL 16

Assisted Solution

AlexNek earned 500 total points
ID: 18888581
"A nullable type can represent the normal range of values for its underlying value type, plus an additional null value"

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?.

LVL 16

Expert Comment

ID: 18888584
You type more quickly. :)

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

623 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