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

    }

  • 相关阅读:
    查看数据库中指定用户下每个表占的实际空间大小
    数据库中查询列数据是否有重复
    oracle查看数据库的字符集
    【转】oracle数据库中varchar2陷阱
    cursor详解
    vs报算术运算溢出的错误
    count(1)比count(*)效率高
    基于NPOI的Execl导入导出例子
    day4-2数组及方法
    day4-1深入理解对象之创建对象
  • 原文地址:https://www.cnblogs.com/handboy/p/7148498.html
Copyright © 2011-2022 走看看