什么是“多长时间?”数据类型? [英] What is 'long?' data type?
问题描述
我要在其他开发人员编写一些代码,我不知道是什么长
表示:
保护字符串AccountToLogin(?长ID)
{
串LOGINNAME =;
如果(id.HasValue)
{
试
{....
长
相同的Int64
的
?
意味着它是可空
一个可空类型可以表示其
标的值类型值
正常范围,加上
附加空值
块引用>
可空例如:
诠释? NUM = NULL;
如果(num.HasValue ==真)
{
的System.Console.WriteLine(数=+ num.Value);
}
,否则
{
的System.Console.WriteLine(NUM =空);
}
这允许你居然查了
空
值,而不是试图分配的东西任意值进行检查,看看是否有失败。
其实,我写了一篇博客文章中针对此<一个HREF =http://robertgreiner.com/2010/04/write-better-code-using-nullable-with-csharp/>这里。
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 {....
解决方案
long
is the same asInt64
The
?
means it is nullableA 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.
这篇关于什么是“多长时间?”数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!