Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Comparing String Builder objects in C#

You can directly compare two or more String Builder objects without converting to anything else.

  1. using System;
  2. using System.Text;
  3.  
  4. namespace forgetCode
  5. {
  6. class program
  7. {
  8. public static void Main()
  9. {
  10.  
  11. StringBuilder sb1 = new StringBuilder("Time is gold");
  12.  
  13. StringBuilder sb2 = new StringBuilder("Time is gold");
  14.  
  15. if (sb1.Equals(sb2))
  16. {
  17. Console.WriteLine("Matches");
  18. }
  19. else
  20. Console.WriteLine("Not Matching");
  21.  
  22. }
  23. }
  24. }


Output:
Matches

  1. using System;
  2. using System.Text;
  3.  
  4. namespace forgetCode
  5. {
  6. class program
  7. {
  8. public static void Main()
  9. {
  10.  
  11. StringBuilder sb1 = new StringBuilder("Time is gold");
  12.  
  13. StringBuilder sb2 = new StringBuilder("Time is silver");
  14.  
  15. if (sb1.Equals(sb2))
  16. {
  17. Console.WriteLine("Matches");
  18. }
  19. else
  20. Console.WriteLine("Not Matching");
  21.  
  22. }
  23. }
  24. }


Output:
Not Matching