Different between equality operator (==) and equals() methods in C#
Loading
Different between equality operator (==) and equals() methods in C#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Nov 9, 2022, 1:11 PM EST
The Equality Operator ( ==) is the comparison operator and the Equals() method in C# is used to compare the content of a string.
The Equals() method compares only content.
Abhishek SinghalRank #508 · 4.8K reputationPosted Nov 9, 2022, 11:50 PM EST
Hi Naresh,
equals() method compare the content of two string whereas the == operator checks the reference of the string object.
Please look at the below example
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Hello { internal class Program { static void Main(string[] args) { String str1 = "Hello"; String str2 = "Hello"; String str3 = "Hello1"; Console.WriteLine(str1==str2); Console.WriteLine(str2==str3); String str4 = "Happy Learning"; String str5 = "Happy Learning"; Console.WriteLine(str4.Equals(str5)); Console.ReadLine(); } } }The Output will be :
True
False
True
NitinRank #140 · 16.1K reputationPosted Nov 10, 2022, 12:34 AM EST
https://www.c-sharpcorner.com/UploadFile/3d39b4/difference-between-operator-and-equals-method-in-C-Sharp/
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 10, 2022, 12:55 AM EST
https://www.c-sharpcorner.com/Blogs/difference-between-operator-and-equals-method