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

写一个ss|dd|ff的练习。有问题求解!
如上所诉
  static void Main(string[] args)
  {
  string[] s = { "ss", "dd", "ff" };
  string t = "|";
  string st = sum(s, t);
  Console.Write(st);
  Console.ReadKey();
   
  }
  static string sum(string[] x, string y)
  {
  string ss = "";
  for (int i = 0; i < x.Length - 1; i++)
  {
  ss = ss + x[i] + y;
  }
  return ss;
  }

写到了这运行结果: ss|dd| 请问最后一个元素怎么添加进去?

------解决方案--------------------
探讨

需要这么麻烦吗?

C# code

static void Main(string[] args)
{
string[] s = { "ss", "dd", "ff" };
Console.Write(String.Join("|", s));
Console.ReadKey();
}

------解决方案--------------------
探讨

如果是应用,那这么写最好,如果是……