Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Possible unintended reference comparison

Reply
Thread Tools

Possible unintended reference comparison

 
 
sotec
Guest
Posts: n/a
 
      12-30-2005


erroe message and code portion is like this....
how can i change this code to not occur to error

if (page.Session["UserId"] == null || page.Session["UserId"] !=
userId )
{
UserStatusSetting(page, userId);
}

Warning 2 Possible unintended reference comparison; to get a value
comparison, cast the left hand side to type 'string'
c:\inetpub\wwwroot\Minks\App_Code\SessionManager\S iteSessionManager.cs 28 51
http://localhost/Minks/


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      12-30-2005
Sotec,
When you refer to an object that is stored in Session State, it doesn't
^automatically^ assume its initial type from when you stored it there. So
for example, (if your userId is a string) you could use
(string)page.Session["UserId"] and now you would be comparing a string to a
string.
Hope that helps.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"sotec" wrote:

>
>
> erroe message and code portion is like this....
> how can i change this code to not occur to error
>
> if (page.Session["UserId"] == null || page.Session["UserId"] !=
> userId )
> {
> UserStatusSetting(page, userId);
> }
>
> Warning 2 Possible unintended reference comparison; to get a value
> comparison, cast the left hand side to type 'string'
> c:\inetpub\wwwroot\Minks\App_Code\SessionManager\S iteSessionManager.cs 28 51
> http://localhost/Minks/
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible unintended interpolation of @$ in string jidanni@jidanni.org Perl Misc 2 04-29-2009 05:32 PM
Unintended Consequences steve NZ Computing 0 09-21-2006 12:07 PM
GCC-Bug ? (Unintended "overloading") Andreas Griesmayer C Programming 20 08-02-2006 01:20 AM
Unintended inheritance Kay Schluehr Python 2 02-24-2006 04:56 PM
Spyware and unintended consequences Governor Swill Computer Support 4 01-11-2005 07:24 AM



Advertisments