Solved

Difference between int? and int decleration ??

Posted on 2007-04-11
3
248 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set value of dynamically created checkboxlist 2 32
C# Desktop Application 3 32
InputLanguage 1 26
Switching Visual Studio 2015 to normal debug display 3 26
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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