要检查两个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