为什么你可以指定任何VB.NET中的整数? [英] Why can you assign Nothing to an Integer in VB.NET?
本文介绍了为什么你可以指定任何VB.NET中的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我允许分配没有
来的值类型在VB.NET:
暗淡x作为整数=没有
但我不能分配空
在C#中:
INT X = NULL;
解决方案
在您指定没有
来在VB.Net它实例化类型,其默认值值类型。因此,在这种情况下,你没有创建一个空的整数,但持有0
的默认值的整
Why am I allowed to assign Nothing
to a value-type in VB.NET:
Dim x as Integer = Nothing
But I'm not allowed to assign null
in C#:
int x = null;
解决方案
When you assign Nothing
to a value type in VB.Net it instantiates that type with its default value. So in this case you're not creating a null integer, but an integer that holds the default value of 0
这篇关于为什么你可以指定任何VB.NET中的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文