读书人

string[]args有什么用的?小弟我注释掉

发布时间: 2012-08-13 13:21:53 作者: rapoo

string[]args有什么用的?我注释掉那三行也没错啊
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{

string spath;
// if (args.Length == 0)
spath = Directory.GetCurrentDirectory();
// else
// spath = args[0];


showfiledetail(spath);
Console.ReadKey();
}
public static void showfiledetail(string spath)
{
string[]files=Directory.GetFiles(spath);
foreach (string sfile in files)
{
Console.WriteLine(getrelativename(sfile));
}
}
public static string getrelativename(string spath)
{
int pos;
Console.WriteLine(spath);
for (pos = spath.Length - 1; pos > 0; pos--)
{
if (spath[pos] == '\\')
break;
Console.WriteLine("pos={0} ;spath[pos]={1}",pos,spath[pos]);
}
if (pos==spath.Length-1)
return spath;
else
return spath.Substring(pos+1,spath.Length-pos-1);

}
}

}
有大神带我加我qq就最好了,yahoo~~~~~

[解决办法]
string[] args是接收命令行参数的,去掉可以
[解决办法]
有些程序可以使用命令行参数来实现一定的功能。
你这个程序没用到就不需要了。
调用exe时如果xxx.exe abc的话args[]里就有值了

探讨
引用:

string[] args是接收命令行参数的,去掉可以

书上他没事写出来耍我咯?问题白问了。是不是我开始输入abc,回车,然后args[0]被赋值为abc啊?是不是这样理解的

读书人网 >C#

热点推荐