2015-02-06 175 views
0

我已经实现了一个自定义链表,并且我在实现IEnumerator <>时遇到了问题。具体来说,编译器告诉我The name "GetEnumerator" does not exist in the current context。我觉得我正在实现它,正是我在许多计算器上发布的帖子和教程中看到的,我错过了什么?在这种情况下GetEnumerator不存在

这里是我的数据结构:

namespace TestReportCreator_v3 
{ 
    public class FindingsTable : IEnumerable<string> 
    { 
     private Node head, mark; 
     public class Node 
     { 
      public string description; //covers weakness, retinaDesc, nessusDesc 
      public string riskLevel; //covers impactLevel, retinaRisk, nessusRisk 
      public string boxName; //box name results apply to 
      public string scanner; //wassp, secscn, retina, nessus 
      public string controlNumber; //ia control number impacted, wassp and secscn only 
      public string fixAction; //comments, retinaFix, nessusSolu 
      public string auditID; //nessus plugin, retina AuditID, wassp/secscn test number 
      public Node next; 
      public Node(string auditID, string riskLevel, string boxName, string scanner, string controlNumber, string fixAction, string description, Node next) 
      { 
       this.description = description; 
       this.riskLevel = riskLevel; 
       this.boxName = boxName; 
       this.scanner = scanner; 
       this.controlNumber = controlNumber; 
       this.fixAction = fixAction; 
       this.auditID = auditID; 
       this.next = next; 
      } 
     } 

    ...insert, delete, update, save methods... 

     public IEnumerator<string> IEnumerable<string>.GetEnumerator() 
     { 
      var node = mark; 

      while (node != null) 
      { 
       yield return node.riskLevel; 
       node = node.next; 
      } 
     } 

     System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 
     { 
      return GetEnumerator(); 
     } 
    } 
} 
+3

边注:很奇怪,编译器并没有抱怨'public'中显式接口实现的面前:'公众的IEnumerator 的IEnumerable .GetEnumerator()' – 2015-02-06 16:14:12

+0

增加从下面的答案的信息后,没有尖叫约公众。好决定。谢谢。 – Chris 2015-02-06 17:06:40

回答