String comparisons using Object.Equals() and String.Equals()

It is often confusing that how should we compare the strings and why should one be preferred over others. So to clarify this confusion here are few example which would give you a clear idea that what should be preferred over other.
The very basic approach what we follow is use of == equal operator for string comparisons. Here is why you should not use == equal operator going forward.

Code using == equal operator

[code language=”csharp”]
string str1 = "something";
string str2 = "something";
if (str1 == str2)
{
//Works fine and statements are executed from this block
}
[/code]

Continue reading “String comparisons using Object.Equals() and String.Equals()”