嘿我正在尝试将以下代码从此网页转换为VB.NET
http://msdn.microsoft.com/en-us/magazine/cc163730.aspx
并且有一个转换成这样的方法
' Get the order from the session on demand
Private Shared Function GetOrderFromSession(ByVal i As Integer) As ShoppingCartOrder
Dim session As HttpSessionState = HttpContext.Current.Session
Dim ID As Integer = 0
Dim quantity As Integer = 0
' note: For simplicity session key strings are dynamically
' created——for performance reasons they should be precreated.
ID = CInt(session(ShoppingCartItemIDKeyBase + i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase + i))
Dim item As ShoppingCartItem = ShoppingCartItem.GetItem(ID)
Return New ShoppingCartOrder(item, quantity)
End Function
但是在行周围得到错误
ID = CInt(session(ShoppingCartItemIDKeyBase + i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase + i))
错误1重载解析失败,因为在没有缩小转换的情况下无法调用可访问的“Item”: 'Public Default Property Item(index As Integer)As Object':参数匹配参数'index'从'Double'缩小为'Integer'。 'Public Default Property Item(name As String)As Object':参数匹配参数'name'从'Double'缩小为'String'。
答案 0 :(得分:1)
+运算符可用于字符串连接以及& VB.NET中的运算符,但&符号是首选运算符。
可以肯定的是,您可以将它们切换为&符号并查看错误是否仍然存在? ShoppingCarItemIDKeyBase是一个字符串,我不确定+运算符是否强制字符串转换为数字,因为用户可以选择使用&。
ID = CInt(session(ShoppingCartItemIDKeyBase & i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase & i))
答案 1 :(得分:0)
这些变量中的一个或两个是十进制类型而不是整数: