Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- public delegate void Function<T>(T item);
- public delegate void Function(object item);
- public static class EnumerableExtensions
- {
- public static void For(this IEnumerable enumerable, Function func)
- {
- foreach (object item in enumerable)
- {
- func(item);
- }
- }
- public static void For<T>(this IEnumerable<T> enumerable, Function<T> func)
- {
- foreach (T item in enumerable)
- {
- func(item);
- }
- }
- }
- static void Main(string[] args)
- {
- IEnumerable<int> list = new List<int>() { -5, 3, -2, 1, 2, -7 };
- IEnumerable<bool> isPositiveList = list.Select<int, bool>(i => i > 0);
- foreach (bool isPositive in isPositiveList)
- {
- Console.WriteLine(isPositive);
- }
- Console.ReadKey();
- }
- var res = GetRandomNumbers(100).Take(10)
- .Do(x => Console.WriteLine("Source -> {0}", x))
- .Where(x => x % 2 == 0)
- .Do(x => Console.WriteLine("Where -> {0}", x))
- .OrderBy(x => x)
- .Do(x => Console.WriteLine("OrderBy -> {0}", x))
- .Select(x => x + 1)
- .Do(x => Console.WriteLine("Select -> {0}", x));
- Source -> 96
- Where -> 96
- Source -> 25
- Source -> 8
- Where -> 8
- Source -> 79
- Source -> 25
- Source -> 3
- Source -> 36
- Where -> 36
- Source -> 51
- Source -> 53
- Source -> 81
- OrderBy -> 8
- Select -> 9
- 9
- OrderBy -> 36
- Select -> 37
- 37
- OrderBy -> 96
- Select -> 97
- 97
Add Comment
Please, Sign In to add comment