如何在双变量中设置空值 [英] How to paas a null value in double variable
问题描述
大家好,
如何在双变量中设置空值,例如
Double abc = null;
或Double abc =";
谢谢
mohd wasif
Hi All,
How to paas a null value in double variable e.g.
Double abc=null;
or Double abc="";
thanks
mohd wasif
推荐答案
如果要分配NULL
,请使用Nullable Types
.
例如:
UseNullable Types
if you want to assignNULL
.
For example:
int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = 'a';
有关Nullable Types
的更多信息,请查看以下链接:
http://www.blackwasp.co.uk/CSharpNullableDataTypes.aspx [ http://www.codeguru. com/csharp/csharp/cs_syntax/operators/article.php/c10393/Using-Nullable-Types-in-C.htm [ http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx [ ^ ]
For more information on Nullable Types
look into following links:
http://www.blackwasp.co.uk/CSharpNullableDataTypes.aspx[^]
http://www.codeguru.com/csharp/csharp/cs_syntax/operators/article.php/c10393/Using-Nullable-Types-in-C.htm[^]
http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx[^]
double是一个值类型.值类型实际上没有空值.但是您可以通过使用这种语法获得可为null的double.
double is a value type. value types dont really have null values. but you can have nullable double by using this syntax.
Nullable<Double> d = null;
这将起到双重作用.尝试使用它.只要记住可空类型是不可变的.但是由于您使用的是double,对您来说不会是一个大问题.
P.S.我刚才告诉你的简写是
this will work same as a double. try using it. Just remember nullable types are immutable. but since you are using double it wont be a big problem for you.
P.S. the shorthand of what i just told you is like
Double? d = null;
它的意思是一样的.只是第一个语法糖.
it means the same. just a syntactic sugar for the first one.
这篇关于如何在双变量中设置空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!