using System;
using System.IO;namespace file
{
    class Program
    {
        static void Main(string[] args)
        {
            DriveInfo[] drives = DriveInfo.GetDrives();
            Console.WriteLine("驱动器名\t 类型\t 格式\t 总共空间\t 可用空间");
            foreach (DriveInfo di in drives) 
            {
                Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}"),di.Name,di.DriveType,di.DriveFormat,di.TotalSize,di.TotalFreeSpace);    
            }
        }
    }
}本人初学,书中的例子怎会提示错误讯息如下:
Unhandled Exception: System.FormatException: Index (zero based) must be greaterthan or equal to zero and less than the size of the argument list.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String fo
rmat, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] arg
s)
   at System.String.Format(String format, Object[] args)
   at file.Program.Main(String[] args) in D:\myweb\donet\console\file\file\Progr
am.cs:line 14
Press any key to continue . . .
请问是什么原因?

解决方案 »

  1.   

    搞错了)了,修正完后能正确显示结果,但还是提示错误
    Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}",di.Name,di.DriveType,di.DriveFormat,di.TotalSize,di.TotalFreeSpace));  Unhandled Exception: System.IO.IOException: The device is not ready.   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode)
       at System.IO.DriveInfo.get_DriveFormat()
       at file.Program.Main(String[] args) in D:\myweb\donet\console\file\file\Progr
    am.cs:line 14这又是为啥?
      

  2.   

    The device is not ready google下吧
      

  3.   

    有些盘的一些信息是访问不到的。比如光盘里没有内容时就不能访问TotalFreeSpace。