C-SHARP - 1.5 Exercise: Display

After the theory of the previous video, time to practise. The exercise: print "Bonjour, il fait très beau aujourd'hui" on a single line, but using two different function calls — that is, "Bonjour, " and "il fait très beau aujourd'hui" each handled by its own call. Then below, on a new line, print "Oui effectivement, c'est un temps pour aller faire du sport". Pause the video, try it, then come back for the correction.

To get both halves on the same line, you need a function that does not add a newline at the end. Console.WriteLine adds one; Console.Write does not. So the first half is Console.Write("Bonjour, "); (mind the trailing space — the computer will not insert one for you), and the second half is Console.WriteLine("il fait très beau aujourd'hui");. WriteLine on the second call adds the newline that lets the next sentence appear underneath.

Key takeaways

  • Spaces matter: omit the space after the comma and the two halves are glued together with no separator.
  • Console.Write vs Console.WriteLine: the only difference is the trailing newline added by WriteLine.
  • Anticipate the next line: ending with WriteLine on the first sentence saves you from having to print a manual "\n".

The final step prints the second sentence with Console.WriteLine("Oui effectivement, c'est un temps pour aller faire du sport");. Run the program and you get the first sentence on line 1 — assembled from two calls — and the second sentence on line 2. This drill makes the difference between Write and WriteLine concrete, and it forces you to think about whitespace because the compiler will never add it for you.

Summary

This practical C# lesson teaches how to display text to the console using the output window. Students must write code that outputs the phrase "bonjour il fait très beau aujourd'hui" on a single line from two separate function calls, then display an additional message "Oui effectivement c'est un temps pour faire du sport" on a new line below. The exercise reinforces understanding of console output control and proper string formatting techniques.

Key points

  • Display multiple text outputs on a single line without line breaks using Console.Write()
  • Use separate function calls while maintaining output on the same line
  • Control output formatting to place new messages on separate lines
  • Understand the difference between Console.Write() and Console.WriteLine() for line break management
  • Apply console output techniques to achieve precise formatting requirements

FAQ

How can two separate function calls display text on the same line without a line break between them?

By using Console.Write() instead of Console.WriteLine(), each function call appends to the current line without creating a line break, allowing the console cursor to remain on the same line for subsequent output.

What is the key difference between the first and second messages in this exercise?

The first message 'bonjour il fait très beau aujourd'hui' spans a single line from two separate calls, while the second message must appear on a new line below using appropriate line break control.

Why does this exercise require the output to come from two separate functions rather than one?

The exercise teaches the concept that logical separation in code (different functions) does not necessarily mean separation in output formatting, reinforcing understanding of how Console.Write() and output redirection work independently.