What is 'long?' data type?

左心房为你撑大大i 提交于 2019-12-05 08:26:19

问题


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

回答1:


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.




回答2:


long is an Int64, the ? makes it nullable.




回答3:


long? is a 64-bit, nullable integer.

To clarify, nullable means it can be null or an integer number ( 0, 1, etc.).




回答4:


"long?" is a nullable 64-bit signed integer. It's equivalent to Nullable<Int64>.




回答5:


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.




回答6:


It's a nullable type declaration.



来源:https://stackoverflow.com/questions/3893143/what-is-long-data-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!