-
Book Overview & Buying
-
Table Of Contents
Fundamentals for Self-Taught Programmers
By :
A string is a sequence of characters, made up of letters, numbers, symbols, and spaces. You can think of strings as text. You already worked with strings in the previous chapter when you changed the Hello World message. Strings are enclosed in double quotations and can also be saved as variables.
Let’s update our existing balance application so that it prints some text to the console:
int balance = 75; string balanceMessage = "The current balance is:"; Console.WriteLine(balanceMessage); Console.WriteLine(balance – 40 – 5);
The second line of code has introduced a new variable called balanceMessage, where the type is defined as a string and the value is enclosed in double quotation marks. It is then printed to the console. Here’s a graphical notation:
Figure 6.4 – Identifying the parts of a string variable that has been assigned a value
Now that you know how to create...