c#主程序参数args的问题

using System;
using System.Runtime.InteropServices;

class Test
{
public enum DriveType
{
DRIVE_UNKNOWN=0,
DRIVE_NO_ROOT_DIR=1,
DRIVE_REMOVABLE=2,
DRIVE_FIXED=3,
DRIVE_REMOTE=4,
DRIVE_CDROM=5,
DRIVE_RAMDISK=6
}

static public void Main(string[] args)
{
DriveType driveType = Test.GetDriveType(args[0]);
Console.WriteLine("Drive {0 }is type {1}", args[0], driveType);
}

[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType(string rootPathName);
}

运行后包错:

未处理的异常: System.IndexOutOfRangeException: 索引超出了数组界限。
在 Test.Main(String[] args) 位置 C:\Documents and Settings\孙\My Documents\Vi
sual Studio 2008\Projects\驱动\驱动\api.cs:行号 19
请按任意键继续. . .

这个程序如何把要判别的驱动器参数输入 为什么会索引超出界限~?

这个是需要在命令行里面运行的
你需要打开命令行窗口,然后cd进入程序exe所在目录
然后输入:
test.exe 参数
这样就可以了
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网