开发者

Do i need to convert a sessionvariable to string?

开发者 https://www.devze.com 2023-01-09 18:43 出处:网络
. 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\"?

.

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

精彩评论

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