Compiler Warning (level 2) CS0253
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:
C#
// 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;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: