How do I define an Extension Method for IEnumerable
which returns IEnumerable
?
The goal is to make the Extension Method available for
using System;
using System.Collections.Generic;
namespace ExtentionTest {
class Program {
static void Main(string[] args) {
List BigList = new List() { 1,2,3,4,5,11,12,13,14,15};
IEnumerable Smalllist = BigList.MyMethod();
foreach (int v in Smalllist) {
Console.WriteLine(v);
}
}
}
static class EnumExtentions {
public static IEnumerable MyMethod(this IEnumerable Container) {
int Count = 1;
foreach (T Element in Container) {
if ((Count++ % 2) == 0)
yield return Element;
}
}
}
}