Console.Clear可以用来仅清除行而不是整个控制台? [英] Can Console.Clear be used to only clear a line instead of whole console?

查看:3933
本文介绍了Console.Clear可以用来仅清除行而不是整个控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而关于学校的问题/应答程序的工作,它发生,我认为我可以使用 Console.Clear()来消灭屏幕上的一切。我不知道如果我可以使用到Console.ReadLine(valueOne),那么只输出没有答案的问题。如果我只问了一个问题,在 Console.Clear

While working on a question/answer program for school, it occurred to me that I can use Console.Clear() to wipe out everything on the screen. I wonder if I can use Console.Readline(valueOne), then output only the answer without the question. If I only asked one question, the Console.Clear works.

我有没有值引用几个问题,如果可能的话抹掉。我要离开了问题,只显示几个答案。我想如果我储存的答案,我可以使用 Console.Clear()然后就 Console.WriteLine()与三个变量。我可以做这样的事情:

I have several questions with values not references, to erase if possible. I want to leave out the questions and only display several answers. I think if I store the answers, I could use Console.Clear() then just Console.WriteLine() with three variables. I could do something like this:

Console.WriteLine("Value 1 is: {0:c}" + "Value 2 is: {1:c}" + "Value 3 is: {2:c}, valueOne, valueTwo, valueThree).

问题是引用更容易,因为值被存储和检索。如果我只是使用方法按价值计算,输出的值,主要通过()将不会有一个参考的数值要再次清除和输出。这就是为什么我想知道如果我可以问一个问题,然后删除该行并只输出答案(或答案)。

The problem is easier with references because the values are stored and retrieved. If I simply use methods to pass by value and output the value, main() will not have a reference to those values to clear and output again. That's why I wonder if I can just ask a question, then erase the line and output only the answer (or answers).

我只是想了解的可能性,而不是试图安装一个程序。我想知道输出从参考和值而无需额外的输出问题的值的能力。

I am just trying to understand the possibilities and not trying to setup a program. I like to know the abilities of outputting a value from reference and by value without extra output questions.

推荐答案

您可以使用 Console.SetCursorPosition 函数去一个特定的行号。
比你可以使用这个功能来清除行

Description

You can use the Console.SetCursorPosition function to go to a specific line number. Than you can use this function to clear the line

public static void ClearCurrentConsoleLine()
{
    int currentLineCursor = Console.CursorTop;
    Console.SetCursorPosition(0, Console.CursorTop);
    Console.Write(new string(' ', Console.WindowWidth)); 
    Console.SetCursorPosition(0, currentLineCursor);
}

示例

Console.WriteLine("Test");
Console.SetCursorPosition(0, Console.CursorTop - 1);
ClearCurrentConsoleLine();

更多信息


  • Console.SetCursorPosition方法

  • More Information

    • Console.SetCursorPosition Method
    • 这篇关于Console.Clear可以用来仅清除行而不是整个控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆