Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Warning (level 2) CS0253 

Error Message

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

The compiler is doing a reference comparison. If you want to compare the value of strings, cast the right side of the expression to type.

The following sample generates CS0253:

// CS0253.cs
// compile with: /W:2
using System;
class MyClass
{
   public static void Main()
   {
      string s = "11";
      object o = s + s;

      bool c = s == o;   // CS0253
      // try the following line instead
      // bool c = s == (string)o;
   }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.