我正在寻找在IEnumerable<T> A
中的每一行之前对IEnumerable<T> B
中的所有行进行网格划分的最有效方法。
例如:
A = {A,B}
B = {1,2,3}
网格划分后:
B = {A,1,B,2,A,3}
最佳答案
没有简单的解决方案,但类似的方法可能会起作用。在这里,模数运算符非常重要,以便用较少的项目重复列出的结果。
public static List<object> Mesh<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2)
{
T1[] array1 = s1.ToArray();
T2[] array2 = s2.ToArray();
int length1 = array1.Length;
int length2 = array2.Length;
int maxLength = Math.Max(length1, length2);
List<object> result = new List<object>();
for (int i = 0; i < maxLength; i++)
{
result.Add(array1[i % length1]);
result.Add(array2[i % length2]);
}
return result.
}
关于c# - 网格化IEnumerable <T>一起列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22037637/