具有可为空的int和"if"的奇怪行为.功能. [英] Strange behavior with nullable int and "if" function.

查看:76
本文介绍了具有可为空的int和"if"的奇怪行为.功能.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

考虑以下代码:

Dim x As Integer?
x = If(True, Nothing, 1)

我们可以期望x被设置为Nothing.取而代之的是,我将x设置为0.

We could expect x being set to Nothing. Instead of that, x is set to 0 for me.

不明白为什么.

推荐答案

在VB.Net中,您实例化了一个整数.那个整数是x.但是您不必费心将整数实例化为任何东西,并且默认值为零(0),因此不知道自己在做什么,这是什么问题?

Well in VB.Net you instantiated an Integer. That integer was x. But you didn't bother to instantiate the integer to anything and the default is zero (0) so without knowing what you are doing what is your issue?

你学习不够?编程中的所有内容对您来说都是个谜?您没有足够的时间去阅读,学习和练习课程资料吗?您没有花足够的时间去阅读,学习和练习必备的材料,以至于无法理解 您的课程材料足够.

You didn't study enough? Everything in programming is a mystery to you?  You didn't bother reading and studying and practicing your course material enough? You didn't bother reading and studying and practicing your pre-requisite material enough to understand your course material enough.

我通常会注意到,那些不在乎的人实际上并不在乎什么是必需的,因此将其全部丢弃,这样他们就可以作为无知的实体来做出决定.

I usually notice that people that don't care to know really care less about what is necessary and therefore discard all that so they can make decisions as clueless entities.

所以x =没什么,x没什么呢?零还是不可见?

So x = Nothing and what is Nothing for x? Zero or invisible?


这篇关于具有可为空的int和"if"的奇怪行为.功能.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆