gpt4 book ai didi

c# - 如何使用 GetEnumerator() 实现 IEnumerable

转载 作者:IT王子 更新时间:2023-10-29 04:53:13 25 4
gpt4 key购买 nike

<分区>

我希望我的类型实现 IEnumerable<string> .我试图简而言之遵循 C#,但出了点问题:

public class Simulation : IEnumerable<string>
{
private IEnumerable<string> Events()
{
yield return "a";
yield return "b";
}

public IEnumerator<string> GetEnumerator()
{
return Events().GetEnumerator();
}
}

但是我得到构建错误

Error 1 'EventSimulator.Simulation' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'EventSimulator.Simulation.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'.

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com