12.3. The + Operator and Strings

You can manipulate strings in C# using the StringBuilder class, which is equivalent to the java.lang.StringBuffer class of Java. StringBuilder is a sealed class and therefore cannot be subclassed. Similarly, the StringBuffer class is final and therefore cannot be subclassed. However, instances of the StringBuilder class are not guaranteed to be thread-safe. In Java, StringBuffer methods are synchronized wherever necessary. Listing 12.5 shows StringBuilder in action.

Listing 12.5. A Simple StringBuilder Usage (C#)
 using System; using System.Text; public class StringTest { public static void Main(string[] args) { StringBuilder t = new StringBuilder().Append("It's").Append("My").Append("Life"); Console.WriteLine(t); ...

Get .NET for Java Developers: Migrating to C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.