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);
本文提供了一个使用C#语言在Windows控制台中输出数组元素,并通过|符号进行分隔的程序示例。包括两种方法:直接输出和使用字符串拼接实现分隔。
377

被折叠的 条评论
为什么被折叠?



