Linq Example 8 : Take Nested

3:44 AM
Linq Query:

//Nested Take  
            int[] Numbers1 = { 0, 2, 4, 6, 8 };
            int[] Numbers2 = { 1, 3, 5, 7, 9 };

            var myPair =
                (from n1 in Numbers1
                from n2 in Numbers2
                where n1 > n2
                select new { n1, n2 }).Take(3); //Nested Take - Taking only First Three Pair

            foreach (var t in myPair)
            {
                Console.WriteLine(t.n1.ToString() + " - " + t.n2.ToString());
            }


Output:


2 - 1
4 - 1
4 - 3



0 comments:

Post a Comment