Пример #1
0
        public void generating_numbers()
        {
            var r = MyLinq.ThatAreNotMultipleOf(GetNumbers(0, 100), new long[] { 2, 3 });

            foreach (var v in r)
            {
                Console.WriteLine(v);
            }
        }
Пример #2
0
        public void selecting_numbers()
        {
            var r = GetNumbers(0, 1000)
                    .ThatAreNotMultipleOf(new long[] { 2, 3 })
                    .Where(v => (v % 13) != 0)
                    .Where(v => v.ToString().Contains('8'))
                    .Select(v => v.ToString());

            var r2 = GetNumbers(0, 1000).ThatAreNotMultipleOf(new long[] { 2, 3 });

            double mult = MyLinq.Aggregate(r2, 1.0, (acc, value) => acc * value);

            // Static method.
            var wStatic = MyLinq.Where(r2, FilterThisNumberStatic);
            // Instance method (this is captured).
            var wInstance = MyLinq.Where(r2, FilterThisNumber);

            bool hasAtLeastOne1 = wStatic.Any();
            bool hasAtLeastOne2 = wInstance.Any();


            // Anonymous function.
            int numberOfCallsToDelegate = 0;
            var wDelegate = MyLinq.Where(r2, delegate(long x)
            {
                numberOfCallsToDelegate++;
                return((x % 13) != 0);
            });
            var wLambda = MyLinq.Where(r2, x => (x % 13) != 0);

            // Lambda function.


            foreach (var v in wDelegate)
            {
                Console.WriteLine(v);
            }
            Console.WriteLine(_numberOfCalls);
        }