Possible Duplicate:
== or .Equals()
I have a String Array and just want to count number of splitted string items in the array.
But I can’t decide on which version I want/need/should use:
if(myStringArray.Count.Equals(47))
{
// Do something.
}
or
if(myStringArray.Count == 47)
{
// Do something.
}
Could someone please help me understand the difference between the two approaches and why both ones exist?
I’ve tried both, and both produce the same result.
The
Equalsmethod provides a means for an object type to define “equality” between two instances. With numbers,Equalsand==are the same thing, but when you’re using object types they’re different:Equalscompares equality (are the two objects equivalent to each other), and==compares identity (are the two references to the same object). The class author will overrideEqualsand (typically) compare either all of the object’s fields with the other object’s fields or compare key fields, depending on the class.