C# | Check if two StringBuilder objects are Equal
Last Updated :
03 May, 2022
StringBuilder.Equals Method is used to check whether this instance is equal to a specified object.
Syntax: public bool Equals (System.Text.StringBuilder sb); Here, sb is an object to compare with this instance, or null. Return Value: It will return true if this instance and sb have an equal string, Capacity, and MaxCapacity values; otherwise, false.
Example 1:
csharp
using System;
using System.Text;
class Geeks {
public static void Main(String[] args)
{
StringBuilder st1 = new StringBuilder( "GeeksforGeeks" );
Console.WriteLine(st1.Equals(st1));
}
}
|
Example 2:
csharp
using System;
using System.Text;
class Geeks {
public static void Main(String[] args)
{
StringBuilder st1 = new StringBuilder( "GeeksforGeeks" );
StringBuilder st2 = new StringBuilder( "GFG" );
Console.WriteLine(st1.Equals(st2));
StringBuilder st3 = new StringBuilder();
st3 = st2;
Console.WriteLine(st3.Equals(st2));
}
}
|
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...