C# | Check if two StringBuilder objects are Equal
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:
// C# program to if a StringBuilder object // is equal to another StringBuilder object using System; using System.Text; class Geeks { // Main Method public static void Main(String[] args) { // Create a StringBuilder object // with a String passed as parameter StringBuilder st1 = new StringBuilder("GeeksforGeeks"); // Checking whether st1 is // equal to itself or not Console.WriteLine(st1.Equals(st1)); } } |
chevron_right
filter_none
Output:
True
Example 2:
// C# program to if a StringBuilder object // is equal to another StringBuilder object using System; using System.Text; class Geeks { // Main Method public static void Main(String[] args) { // Create a StringBuilder object // with a String passed as parameter StringBuilder st1 = new StringBuilder("GeeksforGeeks"); // Create a StringBuilder object // with a String passed as parameter StringBuilder st2 = new StringBuilder("GFG"); // Checking whether st1 is // equal to st2 or not Console.WriteLine(st1.Equals(st2)); // Create a StringBuilder object // with a String passed as parameter StringBuilder st3 = new StringBuilder(); // Assigning st2 to st3 st2 = st3; // Checking whether st3 is // equal to st2 or not Console.WriteLine(st3.Equals(st2)); } } |
chevron_right
filter_none
Output:
False True
Reference:
Recommended Posts:
- Check if two Dictionary objects are equal in C#
- C# | Check if two ArrayList objects are equal
- C# | Check if two SortedList objects are equal
- C# | Check if two ListDictionary objects are equal
- Check if two SortedDictionary objects are equal in C#
- C# | Check if two SortedSet<T> objects are equal
- C# | Check if two BitArray objects are equal
- C# | Check if two HashSet<T> objects are equal
- C# | Check if two StringCollection objects are equal
- C# | Check if two HybridDictionary objects are equal
- C# | Check if two StringDictionary objects are equal or not
- C# | Check if two Tuple Objects are equal
- C# | Check if two LinkedList<T> objects are equal
- C# | Check if two OrderedDictionary objects are equal
- C# | Check if two List objects are equal
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



