【发布时间】:2009-07-03 17:20:28
【问题描述】:
我对 Integer.TryParse() 函数的理解是,它试图从传入的字符串中解析一个整数,如果解析失败,结果整数将保持与以前一样。
我有一个默认值为 -1 的整数,如果解析失败,我希望将其保留为 -1。但是,解析失败时的 Integer.TryParse() 函数正在将此默认值更改为零。
Dim defaultValue As Integer = -1
Dim parseSuccess As Boolean = Integer.TryParse("", defaultValue)
Debug.Print("defaultValue {0}", defaultValue)
Debug.Print("parseSuccess {0}", parseSuccess)
我的期望是上面的代码sn-p应该输出:
defaultValue -1
parseSuccess False
然而它却输出:
defaultValue 0
parseSuccess False
我的理解正确吗?
【问题讨论】: