I am going over some code written by another developer and not sure what 'long?' means:
protected string AccountToLogin(long? id)
{
string loginName = "";
if (id.HasValue)
{
try
{....
I am going over some code written by another developer and not sure what 'long?' means:
protected string AccountToLogin(long? id)
{
string loginName = "";
if (id.HasValue)
{
try
{....
long? is a 64 bit, nullable integer
to clarify, nullable means it can be null or an integer number ( 0, 1... etc. )
long
is the same as Int64
The ?
means it is nullable
A nullable type can represent the normal range of values for its underlying value type, plus an additional null value
Nullable example:
int? num = null;
if (num.HasValue == true)
{
System.Console.WriteLine("num = " + num.Value);
}
else
{
System.Console.WriteLine("num = Null");
}
This allows you to actually check for a null
value instead of trying to assign an arbitrary value to something to check to see if something failed.
I actually wrote a blog post about this here.
"long?" is a nullable 64-bit signed integer. It's equivalent to Nullable<Int64>
.
long?
is a nullable type. This means that the id
parameter can have a long value or be set to null
. Have a look at the HasValue
and Value
properties of this parameter.
Got an error attempting to answer: It's a nullable type declaration.