我很感激有人可以帮助找出错误。我在控制台中打印了我的列表项目,我需要向下移动光标,对于要突出显示的每个项目,我已经尝试过这样的操作:
foreach (FileSystemInfo fsi in files)
Console.WriteLine(fsi); //printing the "files" list
Console.SetCursorPosition(0, 0); //setting initial place of cursor
while (Console.ReadKey(true).Key != ConsoleKey.Escape) //untill i press escape
{
switch (Console.ReadKey(true).Key)
{
case ConsoleKey.DownArrow: //for Down key
foreach (FileSystemInfo fsi in files)
{
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Green;
// Here's the problem, the cursor goes to the end of the list,
// not moving through each item:
Console.SetCursorPosition(0, files.IndexOf(fsi));
}
break;
}
}
Console.ReadKey();
我将不胜感激任何帮助!提前致谢!