【发布时间】:2018-08-14 13:12:56
【问题描述】:
我一直认为在 VB.NET 中声明变量会自动将此变量设置为其数据类型的默认值(与 C# 不同)。
那么,之后
-
Dim intValue As IntegerintValue为0 -
Dim dateValue As DatedateValue是 1/1/0001 -
Dim stringValue As StringstringValue是Nothing -
Dim strValue As PointstrValue是 (0; 0)
等等。
但是现在我在循环中声明了一个变量,并且惊讶地发现尽管重复声明该变量保持了它的值。所以,
For index As Integer = 1 To 10
Dim test As Integer
test += 1
Console.WriteLine(test)
Next index
输出从 1 到 10 的数字,而不是输出 1 的十倍。
有人能解释一下为什么吗?这是一个错误还是应该这样工作?
【问题讨论】:
标签: vb.net