Refresh console row with C #

1

I've already asked this same question once, but in that case I needed it for the python language, now I need to solve this same problem with the C # language

I have a loop in C # , and I would like to enter the value of a variable each time it is updated, but I do not want to dirty the console giving print every time and nor clean the entire console .

Is there a way for me to get this result?

int a = 0;
Console.WriteLine("Executando processo:");
while (True) {
    a = a +1
    Console.WriteLine(a);
}

The result at the end of 3 interactions is:

Interaction 1:

$ - Executando processo: 
$ - 1 

Interaction 2:

$ - Executando processo:
$ - 1 
$ - 2

Interaction 3:

$ - Executando processo:
$ - 1 
$ - 2
$ - 3

And I would like to get the following result:

Interaction 1:

$ - Executando processo:
$ - 1 

Interaction 2:

$ - Executando processo:
$ - 2

Interaction 3:

$ - Executando processo:
$ - 3 
    
asked by anonymous 13.12.2017 / 11:57

1 answer

2

You can use Console.Write that prints on the same line. I made use of SetCursorPosition that defines the cursor position on the screen.

a = a + 1;
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write("{0}", a);
Thread.Sleep(1000);
    
13.12.2017 / 12:09