Implementing C# IEnumerablelt;Tgt; for a LinkedList class(实现 C# IEnumerablelt;Tgt;对于 LinkedList 类)
问题描述
I'm trying to write a custom LinkedList class in C# using monoDevelop on Linux, just for the sake of testing and learning. The following code never compiles, and I have no idea why!! It doesn't even tell me what's wrong. All what it says is: Error: The compiler appears to have crashed. Check the build output pad for details. When I go to check the output pad, it's not helpful either: Unhandled Exception: System.ArgumentException: The specified field must be declared on a generic type definition. Parameter name: field
What can I do?
You need to add the non-generic APIs; so add to the iterator:
and to the enumerable:
HOWEVER! If you are implementing this by hand, you are missing a trick. An "iterator block" would be much easier.
The following is a complete implementation; you don't need to write an enumerator class at all (you can remove myLinkedListIterator<T>
completely):
这篇关于实现 C# IEnumerable<T>对于 LinkedList 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!