Possible Duplicate:
C# - Basic question: What is '?' ?
What is the benefit of using int16? Instead of using int16 in .net variable declaration ?
dim i as int16?
dim i as int16
It allows you to have a "null" value. Generic example:
public int MyFunction(int? x)
{
int m = 99;
if(x == null)
m = 0;
else
m /= x.Value;
return m;
}
Otherwise, if try to pass a null value to MyFunction, the compiler will return an error.
Question mark indicates Nullable Types: http://msdn.microsoft.com/en-us/library/1t3y8s4s%28v=VS.100%29.aspx
It isn't really about "benefit" - it is about representing something subtly different; an Int16?
is really just shorthand for Nullable<Int16>
, which means it is capable of representing a null/empty state in addition to the regular Int16
range. But the downside is that it takes more space. So if space efficiency is your aim (which mainly only makes sense in an array, etc) you may want to think carefully.