how to update/ rewrite a line in console (terminal) C#

Feb 24 2013

First of all if you have  searched terminal and C# and you got here, it is called Console my friend! but no worries I got your back anyway, you are in the right place!

Most of us dot-net developers are focused  so much on ASP.net and web-forms and other great futures of dotnet that we are not really expert at  console UI ! Back to our childhood- probably  we can still remember great programs that was made  out of this simple  MS-dos environment. That's why I called  C# console a UI. For things like progress updating, there was not only a counter of digits available  but also a progress bar. Beautiful, simple and as user friendly as possible. Good old days!

Any way I was writing a console program, reading data from documents , progressing them and put them in to database. Eventually, I figured that would be nice to even observe the process and live log. I needed some kind of console that can be updated. first thing I was thinking of  using \r chatterer code or Carriage Return. basically it takes your cursor to the beginning of the line and you can write something else. the implantation would be  like:

Console.Write("\r{0}   ", myString );

But it sounds like you use \n to go to the next  line, instead of using Console.WriteLine method ! I mean who does that !?! Have a little bit dignity ! (I am not sure if it is also programmatically  better to use .WriteLine or not, to me sounds like \n is not really bad at all)

other solutions for return to the beginning of line would be using : 

But you are till welcome to use \r !

Privacy Statement Terms Of Use Copyright 2011 by Rooznamechi