这个例子适用于 .net Framework 2.0 以上版本。

 1     internal class GoodsShelf
 2     {
 3         // 货物列表
 4         string[] goods = { "First thing""Second thing""Third thing""Fourth thing""Fifth thing" };
 5 
 6         /// <summary>
 7         /// 获取迭代器
 8         /// </summary>
 9         /// <returns></returns>
10         public IEnumerator GetEnumerator()
11         {
12             for (int i = 0; i < goods.Length; i++)
13             {
14                 yield return goods[i];
15             }
16         }
17 
18     }

相关文章:

  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2022-01-16
  • 2022-02-10
  • 2021-06-28
  • 2021-12-27
  • 2022-12-23
  • 2021-08-31
相关资源
相似解决方案