检查存储在DriveInfo.Name中的字符串值

时间:2012-04-06 11:41:31

标签: c# .net string

我正在使用以下示例: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

1 个答案:

答案 0 :(得分:1)

您想要d.Name.Contains("T")

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