StringBuilder.Equals方法用于检查此实例是否等于指定的对象。
语法:公共布尔等于(System.Text.StringBuilder sb); 在此, sb是要与此实例进行比较的对象, 或者为null。返回值:如果此实例和sb具有相等的字符串, Capacity和MaxCapacity值, 则返回true;否则返回true。否则为假。【C#检查两个StringBuilder对象是否相等】示例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( "lsbin" );
//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( "lsbin" );
//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));
}
}
输出如下:
FalseTrue
参考:
- https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.equals?view=netcore-2.2
推荐阅读
- C#字符结构用法介绍和示例
- C#检查两个ArrayList对象是否相等
- C#构造函数用法完整介绍和指南
- C#转换类介绍和示例
- C# DateTimePicker类用法示例介绍
- C#字典Dictionary类用法介绍
- C#显式接口实现用法详细介绍
- C# FlowLayoutPanel类用法介绍
- win10设置图文详细教程