我为 LinkedList 创建了一个“反向迭代器”,现在我想将它与扩展方法一起使用:
public static class LinkedListExtensionMethods
{
public static IEnumerator GetReverseEnumerator<T>(this LinkedList<T> linkedList)
{
return new LinkedListReverseEnumerator<T>(linkedList);
}
public static IEnumerator<T> GetReverseGenericEnumerator<T>(this LinkedList<T> linkedList)
{
return new LinkedListReverseEnumerator<T>(linkedList);
}
}
但是,如果我写:
foreach (ICommand command in _CompoundDoCollection.GetReverseEnumerator<ICommand>())
它不起作用。
我应该怎么办?