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

Posted on 2007-10-21
Last Modified: 2013-12-17
Development Platform: c#, 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

    try with:
    return (ViewState["_isChecked"].ToString() == "true");

    Author Comment


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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now