Often, we want to combine strings together, or combine strings with a value that we’ve saved to a variable.
A common way to do is by using string concatenation. String concatenation is when we combine strings using the addition symbol (
+), literally adding one string to another.
string yourFaveMusician = "David Bowie"; string myFaveMusician = "Solange"; Console.WriteLine("Your favorite musician is " + yourFaveMusician + " and mine is " + myFaveMusician + ".");
We write the first part of our string, end it with a double quote (
"), include an addition symbol and then put our variable. However, there are a couple of things to pay attention to:
Let’s use string concatenation to tell a story. Come up with a beginning, middle, and end to a story and save them to the corresponding variables
Concatenate your three strings and store the result in variable named
story to the console.
Are the spacing and punctuation correct? If not, go back and change the
story strings so that it prints correctly.