我有一个GUID叫做"UserID",它需要填充Session("UserID")中的字符串,并格式化为完美的GUID。
如果我尝试这样做,会显示"无法将类型字符串转换为类型 Guid"
Dim UserID As New Guid()
If HttpContext.Current.Session("UserID") IsNot Nothing Then
UserID = HttpContext.Current.Session("UserID")
End If
如果我尝试这样做“无法将字符串类型转换为Guid类型”。
Dim UserID As New Guid()
If HttpContext.Current.Session("UserID") IsNot Nothing Then
UserID = DirectCast(HttpContext.Current.Session("UserID"), Guid)
End If
这将字符串完美地转换为Guid,但它在 If 语句之外无法访问。
If HttpContext.Current.Session("UserID") IsNot Nothing Then
Dim UserID As new Guid(HttpContext.Current.Session("UserID"))
End If
我不知道如何在If语句之外定义UserID,并有条件地进行赋值。
TryParse
返回false的情况。 - Claudio Redi