O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

String Concatenation

Syntactically closely related to arithmetic operations is string concatenation, reusing the + operator notation. The following is an example:

Console.Write("Enter your name: ");string name = Console.ReadLine();string message = "Hello " + name;Console.WriteLine(message);

The way concatenation works internally is by calling into any of the String.Concat static methods, as shown in Figure 5.17.

Image

FIGURE 5.17 String concatenation under the hood.

String concatenation is available not only between two string types but also between a string and any object (System.Object). In that case, ToString is invoked on the object before carrying ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required