喜欢的东西:的多维数组的自定义迭代?
forelement (element G_Element, Grid)
{
Grid[G_Element.dim1, G_Element.dim2] =
new clsGridElement(G_Element.dim1, G_Element.dim2);
}
代替
for (int X = 0; X < GridWidth; X++)
for (int Y = 0; Y < GridHeight; Y++)
Grid[X, Y] = new clsGridElement(X, Y);
如果事情不存在天生,是个可以创造出来的?
感谢, 添
[的foreach(http://msdn.microsoft.com/en-us/library/ttw7t8t6%28v=vs.80%29。 C++); [IEnumerable](http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx)和[yield](http://msdn.microsoft.com/en-us/library/9k7k7cf0 %28v = vs.80%29.aspx)如果你正在编写自己的自定义迭代器。在你的例子中,for循环似乎更简单。 –
查看“C#linq Cartesian product”搜索结果,构造合适的枚举。 Eric Lippert在这里有几个好帖子,像http://stackoverflow.com/questions/4073713/is-there-a-good-linq-way-to-do-a-cartesian-product和http:// stackoverflow .com/questions/4073713/is-there-a-good-linq-way-to-do-cartesian-product and –