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

📅  最后修改于: 2021-05-29 22:07:56             🧑  作者: Mango

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

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

程序1:获取CursorLeft的价值

// C# program to illustrate the
// Console.CursorLeft 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 CursorLeft position
        Console.WriteLine("Current CursorLeft position: {0}",
                                         Console.CursorLeft);
  
        // Get the CursorLeft position
        Console.Write("Current CursorLeft position: {0};",
                                      Console.CursorLeft);
  
        Console.WriteLine(" and now :{0}",
                      Console.CursorLeft);
    }
}
}

输出:

程序2:设置CursorLeft的值

// C# program to illustrate the
// Console.CursorLeft 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 CursorLeft position
        Console.WriteLine("Current CursorLeft position: {0}",
                                         Console.CursorLeft);
  
        // Set the CursorLeft position
        Console.CursorLeft = 25;
  
        // Get the CursorLeft position
        Console.Write("Current CursorLeft position: {0};",
                                      Console.CursorLeft);
    }
}
}

输出: