标签:click 公交车 each get 必须 nta highlight 分享图片 turn
实现效果:
  
知识运用:
通常使用yield return依次返回每个元素 使用yield break语句终止迭代
迭代器的返回值类型必须为IEnumerable或IEnumerator中的任意一种
实现代码:
        public static IList<object> items = new List<object>();     //定义一个泛型对象,用于存储对象
        public static IEnumerable<object> GetValues()
        {
            if (items != null)          //如果泛型不为空
            {
                foreach (object o in items)             //遍历其中对象
                    yield return o;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            foreach(object obj in GetValues()){     //遍历泛型集合
                listBox1.Items.Add(obj.ToString());            //在列表中添加显示信息
            }
        }
标签:click 公交车 each get 必须 nta highlight 分享图片 turn
原文地址:https://www.cnblogs.com/feiyucha/p/10088047.html