What is the difference between == and Equals() for primitives in C#?
Consider this code: int age = 25; short newAge = 25; Console.WriteLine(age == newAge); //true Console.WriteLine(newAge.Equals(age)); //false Console.ReadLine(); Both int and short are primitive types, but a comparison with == returns true and a comparison with Equals returns false. Why? Short answer: Equality is complicated. Detailed answer: Primitives types override the base object.Equals(object) and return true if the boxed object is of the same type and value. (Note that it will also work for nullable types; non-null nullable types always box to an instance of the underlying type.) Since