C# Program to Check Given Strings are Equal or Not Using equal to (==) Operator Last Updated : 11 Nov, 2021 Comments Improve Suggest changes Like Article Like Report Given two strings we need to check if they are equal by using the == operator. The == Operator compares the reference identity i.e. whether they are referring to the same identity in the heap. If they are equal then it will return true, otherwise, return false. Example: Input String 1 : geeks String 2 : geeks Output : Equal Input String 1 : geeks String 2 : geeqs Output : Not Equal Method: For the given two strings compare them by using == operator If it returns true then the strings are equal.If it returns false then the strings are not equal. Example 1: C# // C# program to check given strings are // equal or not. Using == operator using System; class GFG{ public static void Main() { string str1 = "geeks"; string str2 = "geeks"; // Here we use == operator to check // the equality of the strings Console.WriteLine(str1 == str2); } } OutputTrue Example 2: C# // C# program to check given strings // are equal or not. Using == operator using System; class GFG{ public static void Main() { string str1 = "geeks"; string str2 = "geeqs"; // Here we use == operator to check // the equality of the strings Console.WriteLine(str1 == str2); } } OutputFalse But the == operator might not work as expected when we are comparing strings whose reference identities are not the same. Let us understand with the help of the below example: C# // C# program to check given strings // are equal or not. Using == operator using System; class GFG{ static void Main(string[] args) { object str1 = "geeks"; object str2 = new string("geeks"); Console.WriteLine(str1 == str2); } } OutputFalse Comment More infoAdvertise with us Next Article Company Preparation P pulamolusaimohan Follow Improve Article Tags : C# CSharp-programs CSharp-Strings-Programs Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like