将数组元素组合成一个索引

问题描述 投票:0回答:1

我有一个字符串列表,其中的数据如下:

[0] - A
[1] - B
[2] - C

如果列表有多个元素,我可以执行以下操作来计数:

int val = item.Count; //item is the list of string object

现在我正在尝试做这样的事情,不太确定是否可以做到,我一次迭代列表,我的要求如下:

[0] - A
[1] - B
[2] - C

[0] - ABC //Later I can get the length of three

我可以执行以下操作,但希望一次性完成:

string str = "";

foreach(var list in item) //Rather iterating with foreach loop, in one go get the total count of the first index, later the second index
{
   str += list;
}
c# .net
1个回答
0
投票

您可以使用

String.Concat

item = new[]{ String.Concat(item) };
© www.soinside.com 2019 - 2024. All rights reserved.