public void TestSkipEnumerable() { int[] originals = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; IEnumerable <int> odds = originals; // Remove all evens foreach (int original in originals) { odds = new SkipEnumerable <int>(odds, 2 * original); } // Do we have any evens? foreach (int odd in odds) { Assert.AreEqual(1, odd % 2); } }
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)); }