编辑:我尝试过Take/Skip方法,但是我收到以下错误:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to
'string[]'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么因为我复制了赛义德的代码.
我有一个字符串数组(包含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'
Run Code Online (Sandbox Code Playgroud)