Csharp/C Sharp/LINQ/Reverse

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

An Example Calling the Reverse Operator

<source lang="csharp"> using System; using System.Linq; using System.Collections; using System.Collections.Generic; public class MainClass {

   public static void Main() {
       string[] presidents = {"lore", "Truman", "Tailer", "Van", "Washington", "Wilson"};
       IEnumerable<string> items = presidents.Reverse();
       foreach (string item in items)
           Console.WriteLine(item);
   }

}

</source>


Reverse does exactly as it says

<source lang="csharp"> using System; using System.Collections.Generic; using System.Linq; public class MainClass {

   public static void Main() {
       int[] numbers = { 10, 9, 8, 7, 6 };
       IEnumerable<int> reversed = numbers.Reverse();    // { 6, 7, 8, 9, 10 }
   }

}

</source>