I am going over some code written by another developer and am not sure what long?
means:
protected string AccountToLogin(long? id) { string loginName = ""; if (id.HasValue) { try {....
The long data type is used when you need a range of values more than those provided by int. Example: long a = 100000L, long b = -200000L.
Longer integers: long The long data type stores integers like int , but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647. Alternatively, use unsigned long for a range of 0 to 4,294,967,295.
“Long” is a numerical data type in VBA Excel. The long data type in Excel VBA can hold the values from 0 to 2, 147, 483, 647 for positive numbers, and for the negative number it can hold from 0 to -2, 147, 483, 648. VBA Long data type requires 4 bytes of memory storage of your computer.
long
is the same as Int64
long data type
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 Types
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 an Int64, the ?
makes it nullable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With