String Equals() - C# Tutorial
C# Course / Strings / String Equals()

String Equals()

BLUF: Mastering String Equals() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Equals()

C# is a powerful, modern language for enterprise solutions. Discover how String Equals() enhances your development workflow in the guide below.

The C# Equals function is employed to verify if two designated String objects possess identical values. If both strings contain the same value, it will return true; otherwise, it will return false.

In simpler terms, it is employed to evaluate two strings based on their content.

Signature

Example

public bool Equals(String str)
public static bool Equals(String, String)
public override bool Equals(Object)
public static bool Equals(String, String, StringComparison) 
public bool Equals(String, StringComparison)

Parameter

str: it is a string object.

Return

It returns boolean value either true or false.

C# String Equals Method Example

Example

using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
             string s1 = "Hello";  
             string s2 = "Hello";
             string s3 = "Bye";
             Console.WriteLine(s1.Equals(s2));
             Console.WriteLine(s1.Equals(s3));
        }  
    }

Output:

Output

True
False

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience