开发者

Do i need to convert a sessionvariable to string?

.

Session("UserName") = "Sally"  
Dim userName As String = Session("UserName")

Do i need to convert the session variable to str开发者_如何学编程ing if i wanna follow "good coding practices"?

Ex:

Session("UserName") = "Sally"  
Dim userName As String = Convert.ToString(Session("UserName"))


IMO, you should be using

Option Strict On
Option Explicit On

at all times, it makes the compiler yell at you when you cast implicitly or use undeclared identifiers.


Yes as a good practice and if you want to assign to a new variable:

Dim userName As String = Session("UserName")

Otherwise you can use it directly:

Print Session("UserName")

Note that value "Sally" (wrapped in quotes) is a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜