日期:2014-05-18  浏览次数:20733 次

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啊?是不是这样理解的