Data Types
In this section, you will talk about the main data types within C# and their functionalities.
Strings
C# uses the string
keyword to identify data that stores text as a sequence of characters. You can declare a string in several ways, as shown in the following snippet. However, when assigning some value to a string variable, you must place the content between a pair of double quotes, as you can see in the last two examples:
// Declare without initializing. string message1; // Initialize to null. string message2 = null; // Initialize as an empty string string message3 = System.String.Empty; // Will have the same content as the above one string message4 = ""; // With implicit declaration var message4 = "A random message" ;
One simple but effective technique (that you used in the preceding Exercise 1.02) is one called string interpolation. With this technique, it is very simple to mix plain text values with variable values, so that the...