C
C#12mo ago
♫Woozy♫

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
Moods12mo 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♫12mo 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
Angius12mo ago
Interpolation being less writing and less ambiguous
Pobiega
Pobiega12mo ago
Always prefer interpolation. And retiring at 65 in todays economy? kekw
Moods
Moods12mo ago
harold
Angius
Angius12mo ago
Not in Fr*nce, that's for sure when