Difference between == and === in C#
Hello everyone! I'm new to C# (previously wrote in JavaScript) and encountered confusion with comparison operators. In JS there is strict comparison === and non-strict ==. In C# I only see ==, but I've heard there are Equals() and ReferenceEquals(). However, I can't find information about === — does it simply not exist? Or is it some syntax I missed?
I tried the following code:
\nint a = 5;\nint b = 5;\nobject objA = a;\nobject objB = b;\n\nConsole.WriteLine(a == b); // True\nConsole.WriteLine(objA == objB); // False (reference comparison?)\nConsole.WriteLine(objA.Equals(objB)); // True (value comparison?)\n\n\nI expected objA == objB to give True, but got
No answers yet.
Log in to leave an answer