检查两个StringBuilder对象在C#中是否相等


本文向大家介绍检查两个StringBuilder对象在C#中是否相等,包括了检查两个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