StringBuilder.Equals方法用于检查此实例是否等于指定的对象。
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.
范例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));
}
}
输出:
True
范例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));
}
}
输出:
False
True
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.text.stringbuilder.equals?view=netcore-2.2