In .Net you could use "==" or .Equals()
== will return true if the reference types are pointing to object in Memory.
.Equals will perform case sensitive and character by character equality check.
StringBuilder a = new StringBuilder("anubhav");
StringBuilder b = new StringBuilder("anubhav");
if (a == b)
Console.WriteLine("a==b is true");
else
Console.WriteLine("a==b is false");
if(a.Equals(b))
Console.WriteLine("a.equals(b) is true");
else
Console.WriteLine("a.equals(b) is false");
Output :
a==b is false
a.equals(b) is true
.Equals will perform case sensitive and character by character equality check.
StringBuilder a = new StringBuilder("anubhav");
StringBuilder b = new StringBuilder("anubhav");
if (a == b)
Console.WriteLine("a==b is true");
else
Console.WriteLine("a==b is false");
if(a.Equals(b))
Console.WriteLine("a.equals(b) is true");
else
Console.WriteLine("a.equals(b) is false");
Output :
a==b is false
a.equals(b) is true
No comments:
Post a Comment