编辑:我尝试了Take/Skip方法,但是出现了以下错误:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to
'string[]'. An explicit conversion exists (are you missing a cast?)
我不知道我做错了什么,因为我复制了Saeed的代码。
我有一个字符串数组(包含20到300个项),我想将其分成2个单独的数组,从第一个数组的中间开始分割。
我知道如何使用for循环来完成这个任务,但我想知道是否有更快/更好的方法。如果数组中有奇数项,我也需要能够正确地将其拆分,例如:
string[] words = {"apple", "orange", "banana", "pear", "lemon"};
string[] firstarray, secondarray;
SplitArray(words, out firstarray, out secondarray); // Or some other function
// firstarray has the first 3 of the items from words, 'apple', 'orange' and 'banana'
// secondarray has the other 2, 'pear' and 'lemon'
.ToArray()
。 - Bob Vale