Figure 4 Providing Iterators on a Generic Linked List
กก
//K is the key, T is the data item
class Node<K,T>
{
   public K Key;
   public T Item;
   public Node<K,T> NextNode;
}
public class LinkedList<K,T> : IEnumerable<T>
{
   Node<K,T> m_Head;
   public IEnumerator<T> GetEnumerator()
   {
      Node<K,T> current = m_Head;
      while(current != null)
      {
         yield return current.Item;
         current = current.NextNode;
      }
   } 
   /* More methods and members */
}