Posted 6 years ago
·
Author
Hello
I'm tinkering with some C# tutorials and trying to figure out this code. I modified the tutorial code because I just wanted to play around with it and see what happened if I changed things around. I'm having lots of fun and loving how things change; however, I'm confused as to why I need to add the work "string" in one section and not the other when the string looks identical.
Why do I need
vs
I took "string" out of the code and I got an error. I only took it out of the first line.
Thank u guys and I hope someone out there can clarify for me. I can't just accept that it has to be this way just because. I need to know the reason or I'll obsess over it.
Edit: I'm aware that and give me the same results. I just wanted to keep the two different codes in here for reference so I remember to look at "string concatenation" in my notes.
I'm tinkering with some C# tutorials and trying to figure out this code. I modified the tutorial code because I just wanted to play around with it and see what happened if I changed things around. I'm having lots of fun and loving how things change; however, I'm confused as to why I need to add the work "string" in one section and not the other when the string looks identical.
string aFriend = "Bill";
Console.WriteLine("Hello " + aFriend);
aFriend = "Maira";
Console.WriteLine($"Hello {aFriend}");
string firstFriend = "Maria";
string secondFriend = "Sage";
string enemy = "Bill";
Console.WriteLine($"My friends are {firstFriend} and {secondFriend} but not {enemy}");
Why do I need
vs
I took "string" out of the code and I got an error. I only took it out of the first line.
Thank u guys and I hope someone out there can clarify for me. I can't just accept that it has to be this way just because. I need to know the reason or I'll obsess over it.
Edit: I'm aware that and give me the same results. I just wanted to keep the two different codes in here for reference so I remember to look at "string concatenation" in my notes.