Guess the result !

Where Simple 1

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers
                where n < 5
                select n ");


Where Indexed

            string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            query = new NLinqQuery(@"
                from n in 
                    digits.Where((digit, index) => index > digit.Length )
                select n");


Take Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Take(3)
                select n");


Skip Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Skip(4)
                select n");


TakeWhile Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.TakeWhile(n => n < 6)
                select n");


SkipWhile Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.SkipWhile(n => n % 3 != 0)
                select n");


Select Indexed

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                from n in numbers.Select((num, index) => new {Num = num, InPlace = (num == index)})
                select n");


Distinct 1

            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                from n in 
                    factorsOf300.Distinct()
                select n");


Union 1

        public void Union1()
        {
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            query = new NLinqQuery(@"
                from n in 
                    numbersA.Union(numbersB)
                select n");


Intersect 1

            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            query = new NLinqQuery(@"
                from n in 
                    numbersA.Intersect(numbersB)
                select n");


Except

            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            query = new NLinqQuery(@"
                from n in 
                    numbersA.Except(numbersB)
                select n");


First

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.First((num, index) => (num % 2 == 0) && (index % 2 == 0))"
                );


Element At

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                (from n in numbers
                where n < 5
                select n ).ElementAt(3)"
                );


Count Simple

            int[] factorsOf300 = { 2, 2, 3, 5, 5 };

            query = new NLinqQuery(@"
                factorsOf300.Distinct().Count() 
            ");


Count Conditional

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 

            query = new NLinqQuery(@"
                numbers.Count(n => n % 2 == 1)
            ");


Count Indexed

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Count((n, index) => n % 2 == index % 2)
            ");


Sum Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Sum()
            ");


Sum Projection

            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Sum(w => w.Length)
            ");


Min Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Min()
            ");


Max Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Max()
            ");


Min Projection

            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Min(w => w.Length)
            ");


Max Projection

            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Max(w => w.Length)
            ");


Average Simple

            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            query = new NLinqQuery(@"
                numbers.Average()
            ");


Average Projection

            string[] words = { "cherry", "apple", "blueberry" };

            query = new NLinqQuery(@"
                words.Average(w => w.Length)
            ");

Last edited Sep 5, 2007 at 3:46 PM by sebastienros, version 2

Comments

No comments yet.