开发环境VS2010

 

WinXP命令行运行C#程序
命令行如下:
WindowsFormsApplication1.exe "c:\ " "c:\"
C#代码如下:
 static void Main(string[] args)
        {
            System.Windows.Forms.MessageBox.Show("参数数量" + args.Length);
            for (int i = 0; i < args.Length; i++)
                System.Windows.Forms.MessageBox.Show(args[i]);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
运行结果如下:
---------------------------

---------------------------
参数数量2
---------------------------
确定  
---------------------------
---------------------------

---------------------------
c:\
---------------------------
确定  
---------------------------
---------------------------

---------------------------
c:"
---------------------------
确定  
---------------------------

可能原因C#把\"当成了转义字符解析成"

 

 

在WinXP上,实验了 文件名和目录名都可以有空格,但末尾的空格会自动忽略掉。

posted on 2022-09-01 20:03  闻缺陷则喜何志丹  阅读(12)  评论(0编辑  收藏  举报  来源