×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - Compare Two Strings Using string.Equals() Method

Given two strings and we have to compare them using String.Equals() method in C#.Net.
[Last updated : March 20, 2023]

string.Equals() Method

It is a method of string class, which is used to compare strings and return either true if they are equal or false, if they are not equal.

Syntax

bool str.Equals(string str);

Return values

  • True - if strings matche.
  • False - if strings do not matche.

C# program to compare two strings using string.Equals() method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
  class Program {
    static void Main() {
      string str = "Hello";

      if (str.Equals("Hello")) {
        Console.WriteLine("Strings is matched");
      } else {
        Console.WriteLine("String is not matched");
      }

      if (str.Equals("Hiii")) {
        Console.WriteLine("String is matched");
      } else {
        Console.WriteLine("String is not matched");
      }
    }
  }
}

Output

String is matched
String is not matched

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.