我有一个IEnumerable<string>我想分成三组,所以如果我的输入有6个项目,我会得到一个IEnumerable<IEnumerable<string>>返回的两个项目,每个项目将包含IEnumerable<string>我的字符串内容.
我正在寻找如何使用Linq而不是简单的for循环
谢谢
我需要在中点将一个不确定大小的数组拆分成两个独立的数组.
使用ToArray()从字符串列表生成数组.
public void AddToList ()
{
bool loop = true;
string a = "";
Console.WriteLine("Enter a string value and press enter to add it to the list");
while (loop == true)
{
a = Console.ReadLine();
if (a != "")
{
mylist.Add(a);
}
else
{
loop = false;
}
}
}
public void ReturnList()
{
string x = "";
foreach (string number in mylist)
{
x = x + number + " ";
}
Console.WriteLine(x);
Console.ReadLine();
}
}
class SplitList …Run Code Online (Sandbox Code Playgroud)