arraylist = [abc, def, ghi, jkl];
我应该如何使用每个语句来获得下面的输出:
firstdata = abc + def
seconddata = ghi, jkl
答案 0 :(得分:0)
List<string> newList = new List<string>();
int index = 0;
string newValue = string.Empty;
foreach (var item in arraylist)
{
newValue += item;
index ++;
if(index == 2)
{
newList.Add(newValue);
index == 0;
}
}
答案 1 :(得分:0)
如果您希望输出为2个单独的列表,则可以通过using System.Linq
var firstData = arraylist.Where((a, i) => i % 4 == 0 || i % 4 == 1);
var secondData = arraylist.Where((a, i) => i % 4 == 2 || i % 4 == 3);
如果您希望输出为连续字符串,则可以使用string.Join()
var firstData = string.Join("", arraylist.Where((a, i) => i % 4 == 0 || i % 4 == 1));
var secondData = string.Join("", arraylist.Where((a, i) => i % 4 == 2 || i % 4 == 3));
答案 2 :(得分:0)
var x=1;
foreach(var item in arraylist){
firstdata += item;
x++;
if(x>2){
seconddata += item;
x=1;
}
}