📜  C#|如何更改控制台的CursorTop

📅  最后修改于: 2021-05-29 13:40:41             🧑  作者: Mango

给定普通的C#控制台,任务是更改控制台的CursorTop。

方法:可以使用C#中System包的Console类中的CursorTop属性来完成此操作。这将更改光标的垂直位置。基本上,它获取或设置光标在缓冲区内的行位置。

程序1:获取CursorTop的价值

// C# program to illustrate the
// Console.CursorTop Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Get the CursorTop position
        Console.WriteLine("Current CursorTop position: {0}",
                                         Console.CursorTop);
  
        // Get the CursorTop position
        Console.Write("Current CursorTop position: {0};",
                                      Console.CursorTop);
  
        Console.WriteLine(" and now :{0}",
                       Console.CursorTop);
    }
}
}

输出:

程序2:设置CursorTop的值

// C# program to illustrate the
// Console.CursorTop Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Get the CursorTop position
        Console.WriteLine("Current CursorTop position: {0}",
                                         Console.CursorTop);
  
        // Set the CursorTop position
        Console.CursorTop = 10;
  
        // Get the CursorTop position
        Console.Write("Current CursorTop position: {0};",
                                      Console.CursorTop);
    }
}
}

输出: