HA

聽說Linq

聽說Linq

using System.Linq;
...
        public static void LinqTest() {
            int[] array = { 1, 5, 2, 10, 7 };
            // Select squares of all odd numbers in the array sorted in descending order
            var results = from x in array
                          where x % 2 == 1
                          orderby x descending
                          select x * x;
            foreach (var result in results) {
                log(result.ToString());
            }
        }
//49 25 1

reference