VB净串联双数据类型
这是我最终解决的奇怪的,但我希望有人可以向我解释为什么会发生:
Public Function s(ByVal SesVarName As String, Optional ByVal SesVal As String = Nothing)
If SesVal IsNot Nothing Then System.Web.HttpContext.Current.Session("" & SesVarName & "") = SesVal
If System.Web.HttpContext.Current.Session("" & SesVarName & "") Is Nothing Then s = Nothing : Exit Function
s = System.Web.HttpContext.Current.Session("" & SesVarName & "")
End Function
s("A",2)
s("B",2)
DIM num as Double = s("A") + s("B")
在上面的情况下,Num返回22 4 ...怪异吧?
s("A",2)
s("B",2)
Dim num1 as Double = s("A")
Dim num2 as Double = s("B")
DIM num as Double = num1 + num2
我猜这与会话变量以及我如何使用函数声明它们有关。我想念/搞砸了该功能?这是因为我自己的利益太聪明了吗?似乎在其他地方工作,这并不意味着什么。
我想我的主要问题是:不应该将num宣布为双重防止串联吗?关于该功能的指针也将不胜感激。
我要过度思考吗?我现在是否应该开始尝试找到我知道我可以加成的双重数据类型的理由?
谢谢
Here's a weird one that I eventually solved but I'm hoping somebody can explain to me why it happened:
Public Function s(ByVal SesVarName As String, Optional ByVal SesVal As String = Nothing)
If SesVal IsNot Nothing Then System.Web.HttpContext.Current.Session("" & SesVarName & "") = SesVal
If System.Web.HttpContext.Current.Session("" & SesVarName & "") Is Nothing Then s = Nothing : Exit Function
s = System.Web.HttpContext.Current.Session("" & SesVarName & "")
End Function
s("A",2)
s("B",2)
DIM num as Double = s("A") + s("B")
In the case above, num is returning 22 but when I hit it with a bigger hammer (below), I can get num to return 4... Weird huh?
s("A",2)
s("B",2)
Dim num1 as Double = s("A")
Dim num2 as Double = s("B")
DIM num as Double = num1 + num2
I'm guessing it has something to do with the session variables and how I'm using a function to declare them. What did I miss/mess up with the function? Is it a matter of being too clever for my own good? It seems to be working elsewhere, not that that really means anything.
I guess my main question is: shouldn't declaring num as Double prevent concatenation? Pointers on the function would be appreciated as well.
Am I overthinking it? Should I just start trying to find reasons to concatenate Double data types now that know I can?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论