How to use C# string Equals

The Equals function within the String Class assumes a fundamental role in facilitating the comparison of two String Object values to determine whether they are identical or not. This function serves as a reliable tool for assessing the equality of two strings, enabling developers to ascertain if the contents of the two string objects are exactly the same.

Using the Equals function in C#, programmers gain a robust mechanism for evaluating the equality of two string values. This functionality proves particularly valuable when dealing with scenarios where precise content matching is crucial, such as data validation or ensuring consistency in information processing.

bool string.Equals(string str1,string str2)
  1. String str1 : The String argument.
  2. String str2 : The String argument.
  1. Boolean : Yes/No.

It return the values of the two String Objects are same

For ex :

Str1 = "Equals()"

Str2 = "Equals()"

String.Equals(Str1,Str2) returns True

String.Equals(Str1.ToLower,Str2) returns False

Because the String Objects values are different

C# String Equals()

The Equals function empowers developers to perform accurate and reliable string comparisons, facilitating the implementation of conditional logic and decision-making based on the equality of string values. By utilizing this functionality, programmers can confidently address scenarios where the exactness of string content is of prime importance, contributing to the creation of robust and dependable software applications.

Full Source C#
using System; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string str1 = "Equals"; string str2 = "Equals"; if (string.Equals(str1, str2)) { MessageBox.Show("Strings are Equal() "); } else { MessageBox.Show("Strings are not Equal() "); } } } }

When you run this C# program you will get message "Strings are Equal() "


The C# String Equals function offers developers a dependable means of assessing whether two String Object values are identical or not. This functionality facilitates precise content matching, empowering developers to implement conditional logic and make informed decisions based on the equality of string values within the C# programming paradigm.