VB净串联双数据类型

发布于 2025-02-03 01:31:04 字数 888 浏览 2 评论 0原文

这是我最终解决的奇怪的,但我希望有人可以向我解释为什么会发生:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文