In course it was written as Console.WriteLine(""); statements are in sequence, despite being on seperate lines all will be printed in the same line but my compiler printed them in different lines.

Abhishek Kumar 20 Reputation points
2024-12-29T04:20:26.27+00:00

Console.WriteLine("the world dies");

Console.WriteLine(" .");

should have printed

the world dies .

but it printed

the world dies

 .

This question is related to the following Learning Module

.NET Training
.NET Training
.NET: Microsoft Technologies based on the .NET software framework.Training: Instruction to develop new skills.
16 questions
{count} votes

Accepted answer
  1. Pradeep M 4,715 Reputation points Microsoft Vendor
    2024-12-29T09:42:37.82+00:00

    Hi Abhishek Kumar,

    Thank you for reaching out to Microsoft Q & A forum. 

    The issue arises because Console.WriteLine() automatically appends a new line after printing each statement, which causes the output to appear on separate lines. To ensure everything is printed on the same line, you can use Console.Write() instead, as it does not add a new line after the output. Alternatively, you can combine the text into a single Console.WriteLine() statement, such as Console.WriteLine("the world dies .");, to produce the desired result. Use the appropriate method depending on whether you want the output to continue on the same line or start a new one. 

    Screenshot for your reference: User's image

    Please feel free to contact us if you have any additional questions.     

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.        

    Thank you.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.