Reverse

public static IEnumerable<T> Reverse<T>(this IEnumerable<T> items)
        {
            IList<T> list = (IList<T>) items;
            
            if (list == null) 
                yield return default(T);

            for (int i = list.Count - 1; i >= 0; i--)
            {
                yield return list[i];
            }
        }
 
Example:
List<string> list = new List<string>();
list.add("a");
list.add("b");

foreach (string item in list.Reverse<string>()
{
//todo: item
}

Description

Reverses the order of the list that you wish to enumerate.

Details

Double click on the code to select all.

 

;