c# - 反之foreach

标签 c# loops foreach

有没有办法让 foreach 从头到尾遍历整个集合?

int[] fibarray = new int[] { 0, 1, 2, 3, 5, 8, 13 };
    foreach (int i in fibarray)
    {
        System.Console.WriteLine(i);
    }

如何用foreach反转显示?

最佳答案

using System.Linq;

foreach (int i in fibArray.Reverse())

但是普通的 for 循环会更有效率:

for( int index = fibArray.Length - 1; index >= 0; --index ) {
    int i = fibArray[index];
    ...
}

关于c# - 反之foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6564387/

相关文章:

c# - 线程如何相互通信?

c# - 如何将数据集的内容存储在字符串变量中?

c# - Wpf DataGrid 只显示空行

c# - 枚举器问题,有什么办法可以避免两个循环?

c# - 运行C#几分钟后计时器错误

xslt - 你可以使用<xsl :for-each> to go through attributes?

javascript - 遍历分块元素

c# - 突然我的 web-api 项目找不到对 System.Web.Mvc 的引用,编译正常但运​​行时错误

java - 在循环下从数组填充 jtable

javascript - Apply.prototype.push.apply 与 forEach 对于嵌套数组?