Check if two StringBuilder objects are Equal in C#

CsharpServer Side ProgrammingProgramming

To check if two StringBuilder objects are equal, the code is as follows −

Example

 Live Demo

using System;
using System.Text;
public class Demo {
   public static void Main(String[] args){
      StringBuilder strBuilder1 = new StringBuilder("Tim");
      StringBuilder strBuilder2 = new StringBuilder("Tom");
      StringBuilder strBuilder3 = new StringBuilder();
      strBuilder2 = strBuilder3;
      Console.WriteLine("Is StringBuilder3 equal to StringBuilder2? = "+strBuilder3.Equals(strBuilder2));
   }
}

Output

This will produce the following output −

Is StringBuilder3 equal to StringBuilder2? = True

Example

Let us see another example −

 Live Demo

using System;
using System.Text;
public class Demo {
   public static void Main(String[] args){
      StringBuilder strBuilder1 = new StringBuilder("Jacob");
      StringBuilder strBuilder2 = new StringBuilder("Jacob");
      Console.WriteLine("Is StringBuilder1 equal to StringBuilder2? = "+strBuilder2.Equals(strBuilder1));
   }
}

Output

This will produce the following output −

Is StringBuilder1 equal to StringBuilder2? = True
raja
Published on 05-Dec-2019 11:19:23
Advertisements