Strings

It is nearly impossible to write a C# program without creating strings, and we wouldn’t want to deprive you of them here. Strings are actually complex classes that we’ll cover much more thoroughly in Chapter 15. For now, though, all you need to know is that a string object holds a series of characters.

You declare a string variable using the string keyword much as you would create an instance of any type:

string myString;

You specify a string literal by enclosing it in double quotes:

"Hello World"

You already used a string literal back in Chapter 1, in the Hello World example.

You’ll frequently initialize a string variable by assigning it a string literal:

string myString = "Hello World";

Get Learning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.