博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
代码清单3-10 一个完整的泛型枚举——从0枚举到9
阅读量:7254 次
发布时间:2019-06-29

本文共 1315 字,大约阅读时间需要 4 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            CountingEnumerable counter = new CountingEnumerable();            foreach (int x in counter)            {                Console.WriteLine(x);            }            Console.ReadKey();        }    }    class CountingEnumerable : IEnumerable
{ public IEnumerator
GetEnumerator() { return new CountingEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } class CountingEnumerator : IEnumerator
{ int current = -1; public int Current { get { return current; } } object System.Collections.IEnumerator.Current { get { return Current; } } public bool MoveNext() { current++; return current < 10; } public void Reset() { current = -1; } public void Dispose() { } }}

 

转载于:https://www.cnblogs.com/liuslayer/p/6953040.html

你可能感兴趣的文章
【转】android JNI编程 一些技巧(整理)
查看>>
MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作
查看>>
各种排序算法汇总
查看>>
C#巧用Excel模版变成把Table打印出来
查看>>
SOAP 及其安全控制--转载
查看>>
JarSearch
查看>>
[Unity3D][Vuforia][IOS]vuforia在unity3d中添加自己的动态模型,识别自己的图片,添加GUI,播放视频...
查看>>
Freemodbus介绍及测试
查看>>
[转]Phantomjs实现获取网页快照并生成缩略图
查看>>
leveldb源码学习系列
查看>>
Linux 运行 apt-get install 就出现jdk installer 错误的解决方法
查看>>
Android OpenGL ES(九)绘制线段Line Segment .
查看>>
Ubuntu下安装配置JDK1.7
查看>>
转载:STM32之中断与事件---中断与事件的区别
查看>>
[裴礼文数学分析中的典型问题与方法习题参考解答]4.5.10
查看>>
设计模式(十四)单例模式(创建型)
查看>>
JAVA修饰符类型(public,protected,private,friendly)
查看>>
haxm intelx86加速模拟器的安装
查看>>
(ETW) Event Tracing for Windows 入门 (含pdf下载)
查看>>
OSSEC
查看>>