public void MapEnumerableExample() { // Square every element of a lst int[] nums = new int[] { 1, 2, 3 }; IEnumerable <int> squared = new MapEnumerable <int, int>(nums, SquareIt, null); // Writes: 1, 4, 9 Console.WriteLine(EnumerableUtilities.JoinEnumerator(", ", squared)); }
public void AppendEnumerableExample() { // Append the following two lists int[] one2three = new int[] { 1, 2, 3 }; int[] four2six = new int[] { 4, 5, 6 }; IEnumerable <int> appended = new AppendEnumerable <int>(one2three, four2six); // Writes: 1, 2, 3, 4, 5, 6 Console.WriteLine(EnumerableUtilities.JoinEnumerator(", ", appended)); }
public void SkipEnumerableExample() { // Remove all the square numbers int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; IEnumerable <int> squareless = nums; foreach (int num in nums) { double sqrt = Math.Sqrt(num); if (sqrt == Math.Round(sqrt)) { squareless = new SkipEnumerable <int>(squareless, num); } } // Writes: 2, 3, 5, 6, 7, 8 Console.WriteLine(EnumerableUtilities.JoinEnumerator(", ", squareless)); }