zoukankan      html  css  js  c++  java
  • 重新复习基础草稿:迭代器的使用

    原文发布时间为:2008-12-05 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Collections;

    namespace fanxing1
    {
        class Class1
        {
            static void Main()
            {
                ListClass listClass1 = new ListClass();

                foreach (int i in listClass1)
                {
                    System.Console.WriteLine(i);
                }

                foreach (int n in listClass1.SampleIterator(50,60))
                {
                    System.Console.WriteLine(n);
                }

                SampleCollection col = new SampleCollection();
                // Display the collection items:
                System.Console.WriteLine("Values in the collection are:");
                foreach (int i in col.BuildCollection())
                {
                    System.Console.Write(i + " ");
                }

                Console.ReadLine();
            }
        }

        public class ListClass
        {
            public IEnumerator GetEnumerator()
            {
                for (int j = 0; j < 10; j++)
                {
                    yield return j;
                }
                yield return 96;
                yield return 100;
            }

            public IEnumerable SampleIterator(int start, int end)
            {
                for (int i = start; i <= end; i++)
                {
                    yield return i;
                }
            }
         
        }

        public class SampleCollection
        {
            public int[] items;

            public SampleCollection()
            {
                items = new int[5] { 5, 4, 7, 9, 3 };
            }

            public IEnumerable BuildCollection()
            {
                for (int i = 0; i < items.Length; i++)
                {
                    yield return items[i];
                }
            }
        }

    }

  • 相关阅读:
    根据dateFormatter创建NSDate类型数据
    centos6.5下oracle自动备份删除指定天数的文件
    svg-edit和svg中的自定义属性
    vc读取当前路径和读取配置ini文件
    powerdesiner技巧
    oracle理解和导入导出
    highstock无图像
    winform中datagridview刷新后的排序记忆
    freemarker取数
    winform clickonce在线安装
  • 原文地址:https://www.cnblogs.com/handboy/p/7148498.html
Copyright © 2011-2022 走看看