C# GetEnumerator在此上下文中不存在

C# GetEnumerator在此上下文中不存在,c#,linked-list,ienumerable,ienumerator,C#,Linked List,Ienumerable,Ienumerator,我已经实现了一个自定义链表,但是我在实现IEnumerator时遇到了问题。具体地说,编译器告诉我当前上下文中不存在名称“GetEnumerator”。我觉得我正在实现它,就像我在许多stackoverflow帖子和教程中看到的那样,我遗漏了什么 以下是我的数据结构: namespace TestReportCreator_v3 { public class FindingsTable : IEnumerable<string> { private N

我已经实现了一个自定义链表,但是我在实现IEnumerator时遇到了问题。具体地说,编译器告诉我当前上下文中不存在名称“GetEnumerator”。我觉得我正在实现它,就像我在许多stackoverflow帖子和教程中看到的那样,我遗漏了什么

以下是我的数据结构:

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();
        }
    }
}
命名空间TestReportCreator\u v3
{
公共类查找稳定:IEnumerable
{
私有节点头、标记;
公共类节点
{
公共字符串描述;//包含弱点、retinaDesc、nessusDesc
公共字符串riskLevel;//包括IMPACTELEVEL、retinaRisk、nessusRisk
公共字符串boxName;//框名称结果适用于
公共字符串扫描仪;//wassp、secscn、视网膜、nessus
公共字符串controlNumber;//受影响的ia控制号,仅wassp和secscn
公共字符串fixAction;//注释,retinaFix,nessusolu
公共字符串试听;//nessus插件,视网膜试听,wassp/secscn测试编号
公共节点下一步;
公共节点(字符串试听、字符串风险级别、字符串框名称、字符串扫描程序、字符串控制编号、字符串修复操作、字符串描述、节点下一步)
{
this.description=描述;
this.riskLevel=riskLevel;
this.boxName=boxName;
this.scanner=扫描器;
this.controlNumber=controlNumber;
this.fixAction=fixAction;
this.audited=audited;
this.next=next;
}
}
…插入、删除、更新、保存方法。。。
公共IEnumerator IEnumerable.GetEnumerator()
{
var节点=标记;
while(节点!=null)
{
收益率-收益率-风险水平;
node=node.next;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
返回GetEnumerator();
}
}
}
IEnumerable.GetEnumerator()是一个显式接口实现,因此需要在实例上调用它,作为接口访问。要做到这一点,最简单的方法是施放
this

return ((IEnumerable<string>)this).GetEnumerator();
返回((IEnumerable)this).GetEnumerator();
请参阅以获取替代方案。

IEnumerable.GetEnumerator()
是一个显式接口实现,因此需要在实例上调用它,作为接口访问。要做到这一点,最简单的方法是施放
this

return ((IEnumerable<string>)this).GetEnumerator();
返回((IEnumerable)this).GetEnumerator();

请参阅以获取替代方案。

旁注:奇怪的是,编译器在显式接口实现之前没有抱怨
public
public IEnumerator IEnumerable.GetEnumerator()
在添加下面答案中的信息后,它确实对public大喊大叫。好电话。谢谢。旁注:奇怪的是,编译器没有在显式接口实现之前抱怨
public
public IEnumerator IEnumerable.GetEnumerator()
在添加下面答案中的信息后,它确实对public发出了尖叫。好电话。非常感谢。