0

我使用的示例来自: http: //msdn.microsoft.com/en-us/library/system.io.driveinfo (v=vs.80).aspx

将驱动器信息打印到控制台窗口。我想检查 d.Name 是否包含“T”。如果是这样,我不想运行应用程序。如果它什么都不做。这是我一直在尝试的代码。(上面链接示例中的默认代码打印到命令窗口)

(d.Name.IsLetter(T))是我遇到问题的部分。任何人都可以建议吗?

DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);

         if (d.Name.IsLetter(T))
            {
                Console.WriteLine("Run App.");
                notePad.Start();
            }//end if
            else
            {
                Console.WriteLine("Do Nothing.");
            }//end else
        Console.WriteLine("  File type: {0}", d.DriveType);
        if (d.IsReady == true)
        {
            Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
            Console.WriteLine("  File system: {0}", d.DriveFormat);
            Console.WriteLine(
                "  Available space to current user:{0, 15} bytes",
                d.AvailableFreeSpace);

            Console.WriteLine(
                "  Total available space:          {0, 15} bytes",
                d.TotalFreeSpace);

            Console.WriteLine(
                "  Total size of drive:            {0, 15} bytes ",
                d.TotalSize);
        }//end if
    }//end for

}//end main
4

1 回答 1

1

你要d.Name.Contains("T")

有一种Char.IsLetter()方法,但只检查参数是否是“字母”(而不是数字或符号等)

于 2012-04-06T11:44:23.673 回答