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 C# Program to Check Given Strings are Equal or Not Using equal to (==) Operator P pulamolusaimohan Follow Improve Article Tags : C# CSharp-programs CSharp-Strings-Programs Similar Reads C# | Check if two String objects have the same value | Set-1 String.Equals Method method is used to check whether the two String objects have the same value. This method can be overloaded by passing different numbers and types of parameters to it. There are total 5 methods in the overload list of this method in which the first 2 are discussed in this article 3 min read Compare Strings for equality or lexicographical order in different programming Languages Given two strings string1 and string2, the task is to check if these two strings are equal or not. Examples: Input: string1 = âGeeksforGeeksâ, string2 = âGeeksforGeeksâ Output: Yes Input: string1 = âGeeks for Geeksâ, string2 = âGeeks for Geeksâ Output: Yes Input: string1 = âGeeksforGeeksâ, string2 = 8 min read Shell Script To Check the String For a Particular Condition Here, we are going to write a shell script that will echo (print) a suitable message if the accepted string does not meet a particular condition. Suppose we have given some certain conditions then our task is to print the message if the accepted string doesn't match the condition. Example 1: If the 3 min read Comparison Operators in Programming Comparison Operators in programming are used to compare values and determine their relationship, such as equality, inequality, greater than, less than, etc. They evaluate expressions and return a Boolean value (true or false) based on the comparison result, crucial for decision-making in conditional 10 min read Python NOT EQUAL operator In this article, we are going to see != (Not equal) operators. In Python, != is defined as not equal to operator. It returns True if operands on either side are not equal to each other, and returns False if they are equal. Python NOT EQUAL operators SyntaxThe Operator not equal in the Python descrip 3 min read Like