喜歡的東西:的多維數組的自定義迭代?
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 –