实际上,代码片段(.NET 4.7.2;VS 2019 Preview 5.0):
public class CommonFilter
{
private CommonFilter next;
public CommonFilter Next { get { return next; } set { next = value; } }
public CommonFilter GetNext() => next;
}
public class FiltersListEnum<CommonFilter> : IEnumerator<CommonFilter>
{
private CommonFilter current;
public CommonFilter Current => current;
object IEnumerator.Current => this.Current;
public bool EndOfList => (Current?.Next == null);
}
为 EndOfList 属性定义读取器方法时,访问 .Next 会导致编译错误
CS1061“CommonFilter”不包含“Next”的定义,并且找不到接受“CommonFilter”类型作为第一个参数的可访问扩展方法“Next”(可能缺少 using 指令或程序集引用)。
所有定义都是公开的。用 this.Current?.Next 替换 Current?.Next 并没有达到预期的效果。GetNext() 函数也不可用。我摔断了整个脑袋——我做错了什么?
您将类型参数命名为与此处的类完全相同
删除它,你根本不需要它。