将驱动器信息转换为字符串数组时出错



我已经编辑了这个问题,因为前一个问题很模糊,它并没有真正让我得到任何地方,所以这里是编辑:

虽然我把它改成了 Count;而不是 Count((;说实话,它几乎完全被破坏了,而且一团糟,所以我决定废弃数组并重写它:

public static void getdrives()
{
foreach (DriveInfo d in DriveInfo.GetDrives())
{
Console.WriteLine("Please insert USB drive...");
// Here it would await insertion
Console.WriteLine(d + " Drive Detected. Proceed with this drive? (press enter to continue, any other key to cancel.)");
Console.Out.Flush();
if (Console.ReadKey().Key != ConsoleKey.Enter)
{
Console.WriteLine("Are you sure? this will erase all the data on the drive. (press enter to continue, any other key to cancel.)");
if (Console.ReadKey().Key != ConsoleKey.Enter)
{
//do something
}
else
{
Environment.Exit(0);
}
}
}
}

Count是一个属性而不是一个方法,所以你必须使用dlist.Count。请参阅ArrayList类中的Count声明。

// Summary:
//     Gets the number of elements actually contained in the System.Collections.ArrayList.
//
// Returns:
//     The number of elements actually contained in the System.Collections.ArrayList.
public virtual int Count { get; }

最新更新