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

问题描述 投票:-1回答:1

我已经编辑了这个问题,因为之前的问题是一个模糊的问题,它并没有真正让我得到任何好处,所以这里是编辑。

虽然我把它改成了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);
                }
            }
        }
    }
c# .net console-application
1个回答
2
投票

Count 是属性而不是方法,所以你必须使用 dlist.Count. 请看 CountArrayList 类。

// 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; }
© www.soinside.com 2019 - 2024. All rights reserved.