Welcome back.
In this video, I want to show you the difference between string concatenation and string interpolation.
So this what we have here is called string concatenation where we're basically putting strings together.
And we're using variables that we had in between that.
Then automatically so to speak, get converted into a readable string.
And therefore this line works.
Okay.
So that's the cool thing.
We don't need to convert that my number into a string.
Here it is done for us automatically.
However, there is a nicer way to do it which was introduced with C sharp six and makes it a lot easier
for more complex situations where you like basically write very long strings with a bunch of different
variables that you want to have in there.
So let me show you how.
String interpolation.
That's the the word here, how that works.
So basically I'm going to use the same thing that I had here.
But I'm going to use a dollar sign at the beginning, which indicates that I'm going to use interpolation
in the string.
And then instead of using these pluses and breaking down the strings every time, I'm going to use curly
brackets here.
So here I'm saying that this my number should be considered part of the string.
Now I need to do that for the rest as well.
So I'm going to do the same thing for my number two.
And I can get rid of this.
Plus and then it's going to say is and then I'm going to do the same for my sum here as well.
So everything that is of type or is a variable, so to speak, needs to be surrounded by these curly
brackets.
And I need to have a dollar sign at the beginning of my string.
The string is basically what starts with these quotation signs.
So I'm basically saying the result of my number.
And my number two is sum.
And you see the difference between the two.
The thing is, this second variant with string interpolation is less error prone and has been introduced
with C sharp six.
So it's really the better way to go.
And yeah there you see how to do it from now on okay.
This is just a cleaner way.
Both are fine, both work.
But there are sometimes just nicer and cleaner ways to do it.
And string interpolation is the preferred approach because it makes the code more concise and easier
to read.
And that's it for this video.
See you in the next one.