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];
                }
            }
        }

    }

  • 相关阅读:
    JAVA07-Object类、Date类、Calendar类、System类、包装类、Collection、泛型、List、Set、数据结构、Collections
    大话数据结构03-线性表
    大话数据结构02-算法
    大话数据结构01-数据结构序论
    03-移动营销设计-H5设计方法
    02-移动营销设计-设计流程与规范技巧
    字典的定义和操作 (Python)
    列表的系列操作(python)
    列表操作之定义,切片(取元素)(Python)
    python的基础socket知识
  • 原文地址:https://www.cnblogs.com/handboy/p/7148498.html
Copyright © 2011-2022 走看看