检查两个StringBuilder对象在C#中是否相等
要检查两个StringBuilder对象是否相等,代码如下-
示例
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));
}
}
输出结果
这将产生以下输出-
Is StringBuilder3 equal to StringBuilder2? = True
示例
让我们看另一个例子-
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));
}
}
输出结果
这将产生以下输出-
Is StringBuilder1 equal to StringBuilder2? = True
以上是 检查两个StringBuilder对象在C#中是否相等 的全部内容, 来源链接: utcz.com/z/341182.html