Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Possible unintended reference comparison

When i try to check Session["userId"] != null why i get this message Possible unintended reference comparrison; to get value comparrison; cast left hand side to string Any suggestion....

like image 817
ACP Avatar asked May 19 '10 11:05

ACP


2 Answers

Session[key] returns an object, not a string - you should be casting it to string rather than relying on implicit casting or ToString() functionality.

like image 176
slugster Avatar answered Sep 23 '22 17:09

slugster


        if(Session["userId"]!=null)
        {

        }

works just fine for me

like image 31
Sky Sanders Avatar answered Sep 26 '22 17:09

Sky Sanders