Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'long?' data type?

Tags:

c#

nullable

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       {.... 
like image 610
xbonez Avatar asked Oct 08 '10 18:10

xbonez


People also ask

What is long data type example?

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.

What is long data type in C?

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.

What is long data type in Excel?

“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.


2 Answers

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.

like image 95
Robert Greiner Avatar answered Sep 27 '22 23:09

Robert Greiner


long is an Int64, the ? makes it nullable.

like image 39
Lucero Avatar answered Sep 27 '22 22:09

Lucero