Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

Posted on 2007-10-21
Medium Priority
Last Modified: 2013-12-17
Development Platform: c#, asp.net 2.x, Visual Studio Pro utilsiing Web Development, IIS 6

The following code compiles and runs ok -- but I am getting the following compile error (via Visual Studio) -- obviously, I am wanting to have no errors, even if just a warning by the complier.

Your time and efforts with improving this code are much apprieated.

Warning      1      Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

        public bool _isChecked
                if (ViewState["_isChecked"] == null)
                    return false;
                    return (ViewState["_isChecked"] == "true");
                ViewState["_isChecked"] = value;
Question by:amillyard
LVL 55

Accepted Solution

Jaime Olivares earned 2000 total points
ID: 20119064
try with:
return (ViewState["_isChecked"].ToString() == "true");

Author Comment

ID: 20119086

thank you - compile (and works) 1st time without any warning messages :-)

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question