How do I write text, then a int, then more text in the same line?

Trying to have it print "You have sum years left till pension." Console.WriteLine("What's your name?"); string name = Console.ReadLine(); Console.WriteLine($"Hello {name}, how old are you?"); string input = Console.ReadLine(); int num1 = int.Parse(input ); int num2 = 65; int sum = num2 - num1; Console.WriteLine("You have " + sum " years left till pension");
6 Replies
Moods
Moods2y ago
Interpolation works, it’d look like this
Console.WriteLine($”You have {sum} years left till pension”);
Console.WriteLine($”You have {sum} years left till pension”);
♫Woozy♫
♫Woozy♫OP2y ago
Just found out you can also do it like this Console.WriteLine("You have " + sum + " years left till pension"); is there a difference?
Angius
Angius2y ago
Interpolation being less writing and less ambiguous
Pobiega
Pobiega2y ago
Always prefer interpolation. And retiring at 65 in todays economy? kekw
Moods
Moods2y ago
harold
Angius
Angius2y ago
Not in Fr*nce, that's for sure when

Did you find this page helpful?