我已经编辑了这个问题,因为之前的问题是一个模糊的问题,它并没有真正让我得到任何好处,所以这里是编辑。
虽然我把它改成了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
. 请看 Count
在 ArrayList
类。
// 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; }