Changing Foreach Order?
c#, foreach
Solution
using System.Linq;
foreach(var item in source.Reverse())
{
...
}
Edit: There is one more step if you are dealing specifically with a `List<T>`. That class defines its own `Reverse` method whose signature is not the same as the `Enumerable.Reverse` extension method. In that case, you need to "lift" the variable reference to `IEnumerable<T>`:
using System.Linq;
foreach(var item in list.AsEnumerable().Reverse())
{
...
}
Problem
Is there anyway to foreach through a list from the end to the beginning rather than the beginning to then end (preferably without reordering the list).