.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Easy Web
Imran Ghani

Home >> Code Snippets >> OOPS >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Difference between a.Equals(b) and a == b

Posted By:Syed Shakeer Hussain       Posted Date: August 11, 2009    Points: 10    Category: OOPS    URL: http://www.dotnetspark.com  

Both .Equals and == are used for comparison.

If both a and b are value type then then you will get same result in a.Equals(b) and a == b.
but in case of reference type both behaves differently :

string a = new string(new char[] {'d', 'a', 'n', 'c', 'e'});
string b = new string(new char[] {'d', 'a', 'n', 'c', 'e'});
object c = a;
object d = b;

Console.WriteLine (a==b);
Console.WriteLine (a.Equals(b));
Console.WriteLine (c==d);
Console.WriteLine (c.Equals(d));

Output will be:



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend