C# 怎么把字符数组里的元素亮两两合并成新数组,如 a,b,c,d合并成ab,bc,cd

2025-03-25 21:37:43
推荐回答(1个)
回答1:

string[] strs = {"a", "b", "c", "d", "e" };
string[] newStrs = new string[strs.Length - 1];
for (int i = 0, j = 1; i < newStrs.Length; i++, j++)
{
newStrs[i] = strs[i] + strs[j];
}
for (int i = 0; i < newStrs.Length; i++)
{
Console.Write(newStrs[i] + "\t");
}
Console.Read();