2

为什么我在下面的 C# LINQ 代码中收到以下错误

DriveInfo does not exist in current context?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var drives = DriveInfo.GetDrives()
             .Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);
        }
    }
}

提前谢谢了!

4

1 回答 1

5

你需要一个using指令:

using System.IO;

... 导入System.IO.DriveInfo.

于 2012-08-14T13:12:58.480 回答