C# Console question?
Console.SetCursorPosition(0, 0); Console.Write("Hallo Welt"); Console.SetCursorPosition(0, 1); Console.Write("Hallo Du"); Console.SetCursorPosition(0, 0); Console.Write("Your custom message");
I print two messages: "Hello World" and "Hello You" (in two different lines)
Now I want the first message to be replaced with "Your custom message." I thought I'd just move the cursor, retype, and that would be it. I was wrong: The second message, "Hello You," then disappears! Why?
The console then consists only of the message "Your custom message." How do I resolve this?
(And no, I don't want to print "Hello You" again, that would mean that if I wanted to change something in the middle, I would have to cache all the text somehow.)
I can’t reproduce the problem in a Windows console. Instead, the expected target behavior occurs.
Possible reasons that seem to me why it doesn’t work with you:
Interesting. Have it now tried with Windows Terminal (Outside the VS Debug Mode) and the old view from Pre Windows 11 times. Same behavior.
With me it seems as if the current path that appears after the execution slips directly,
I’ll do it like this:
I get issue:
"Your custom message
Allo You"
What happened to the h, no idea!
I can't scroll, no.
The missing H is there when I open the window with the Explorer and not with visual studio run mode. In particular, a “ReadKey” at the end leads me to see my behavior without an additional WriteLine();
I could reproduce it on another computer. Since the cursor is still in the first line, the following lines are overwritten by the system (as is the output of the context path after execution of the application).
Before the end of the program (or after the overwriting) you should put the cursor position back to the end (e.g. into the third line):
What exactly is the problem? Does it work exactly as it should…
Maybe there’s another mistake you can’t find because there’s too little information. Or do I get something wrong?
Compiled and tested on Windows and Linux (Ubuntu)
Try it without ReadKey(); and open it on Windows directly from the terminal, not double-click in the Explorer, otherwise you don’t see anything x)
Both ways tested and running
With me, too. Read the above by what I wrote in answer 😀
That was my problem