static void Main(string[] args)
{
string[] strBtu = { "cc", "vvv", "bbbb", "dd", "ggg", "mmmm" };
string[] strBtu2 = new string[strBtu.Length + strBtu.Length - 1];
int nIndex=0;
for (int i = 0; i < strBtu.Length; i++)
{
strBtu2[nIndex] = strBtu[i];
nIndex++;
if (nIndex < 11)
{
strBtu2[nIndex] = "|";
nIndex++;
}
else
{
break;
}
}
for (int i = 0; i < strBtu2.Length; i++)
{
Console.Write(strBtu2[i]);
}
Console.ReadKey();
}
使用windows控制台程序,输出数组的元素,并且使用“|”分割。
//第二种方法
string s = "";
for (int i = 0; i < strBtu.Length - 1; i++)
{
s = s + strBtu[i] + "|";
}
s = s + strBtu[strBtu.Length - 1];
Console.Write(s);