Comparison of Session and Viewstate with String

Asked

Viewed 122 times

4

Recently, I received the following notice from Visual Studio in a code similar to the image:

inserir a descrição da imagem aqui

I understand what he wanted to say: there is a reference comparison of the two values (the session and the string "test"), and this will always return false, because any value stored in Session will never be referenced in the right string.

But why does it happen? Because Visual Studio was unable to make the comparison without a prior conversion?

PS: The same goes for ViewState

  • tries to put Session["teste"].ToString()

  • Yes, I know it works, but I’d like to know why you need this conversion

1 answer

3


  • So the comparison between two object shall always be of reference unless it is overwritten?

  • Exactly, but reimplementating the operator seems to me something insane.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.