Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'int?' and 'int' in C#?

I am 90% sure I saw this answer on stackoverflow before, in fact I had never seen the "int?" syntax before seeing it here, but no matter how I search I can't find the previous post, and it's driving me crazy.

It's possible that I've been eating the funny mushrooms by accident, but if I'm not, can someone please point out the previous post if they can find it or re-explain it? My stackoverflow search-fu is apparently too low....

like image 673
cori Avatar asked Sep 23 '08 15:09

cori


People also ask

What is the difference between int * and int []?

int* is a pointer to int . It is not an array, but it may represent a start address of an array (or an array iterator — a position inside of an array). int*[] is an array of pointers to int (not array of int s!).

What is the difference between int and int?

A int is a data type that stores 32 bit signed two's compliment integer. On other hand Integer is a wrapper class which wraps a primitive type int into an object. int helps in storing integer value into memory. Integer helps in converting int into object and to convert an object into int as per requirement.

What is int int * in C language?

int. Integers are whole numbers that can have both zero, positive and negative values but no decimal values. For example, 0 , -5 , 10. We can use int for declaring an integer variable.


2 Answers

int? is shorthand for Nullable<int>.

This may be the post you were looking for.

like image 96
Forgotten Semicolon Avatar answered Sep 28 '22 09:09

Forgotten Semicolon


int? is Nullable.

MSDN: Using Nullable Types (C# Programming Guide)

like image 29
KyleLanser Avatar answered Sep 28 '22 09:09

KyleLanser