Ram*_*mie 0 c# arrays sorting list
我可以半信半疑,但我想要一个干净的方式做到这一点,以后不会产生任何麻烦.
private String[][] SplitInto10(string[] currTermPairs)
{
//what do i put in here to return 10 string arrays
//they are all elements of currTermPairs, just split into 10 arrays.
}
Run Code Online (Sandbox Code Playgroud)
所以我基本上想把一个字符串数组(currTermPairs)分成10或11个不同的字符串数组.我需要确保没有数据丢失并且所有元素都已成功传输
编辑:你得到一个n大小的字符串数组.需要发生的是该方法需要从给定的字符串数组返回10个字符串数组/列表.换句话说,将数组拆分为10个部分.
例如,如果我有
A B C D E F G H I J K L M N O P Q R S T U
Run Code Online (Sandbox Code Playgroud)
我需要它分裂成根据其大小10个字符串数组11个或字符串数组,所以在这种情况下,我将不得不
A B
C D
E F
G H
I J
K L
M N
O P
Q R
S T
U <--Notice this is the 11th array and it is the remainder
Run Code Online (Sandbox Code Playgroud)
使用余数%运算符,这里是Linq方法:
string[][] allArrays = currTermPairs
.Select((str, index) => new { str, index })
.GroupBy(x => x.index % 10)
.Select(g => g.Select(x => x.str).ToArray())
.ToArray();
Run Code Online (Sandbox Code Playgroud)
演示(每个数组2个字符串)
| 归档时间: |
|
| 查看次数: |
6499 次 |
| 最近记录: |