using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections; namespace 枚举的实现机制
{
class Program
{
static void Main(string[] args)
{
int[] arr = { ,,,,};
IEnumerator ie = arr.GetEnumerator();
while(ie.MoveNext()==true)
{
int i = (int)ie.Current;
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections; namespace 详细实现机制
{
class ColorEnumerator:IEnumerator//实现IEnumerator接口
{
string[] Colors;
int Position = -;
//实现Current方法
public object Current
{
get
{
if(Position==-)
{
throw new InvalidOperationException();//当前状态无效是引发的异常
}
else if(Position==Colors.Length)
{
throw new InvalidOperationException();
}
return Colors[Position];
}
}
public bool MoveNext()
{
if (Position < Colors.Length - )
{
Position++;
return true;
}
else
{
return false;
}
}
public void Reset()
{
Position = -;
}
public ColorEnumerator(string[]theColors)
{
Colors=new string[theColors.Length];
for (int i = ; i < theColors.Length;i++ )
{
Colors[i]=theColors[i];
Console.WriteLine(Colors[i]);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 详细实现机制
{
class Program
{
static void Main(string[] args)
{
string[] arr = { "Red", "Blue", "Yellow", "Green", "Gray", "Orange" };
ColorEnumerator color = new ColorEnumerator(arr);
Console.ReadKey();
}
}
}

手动书写小代码-foreach实现机制的更多相关文章

  1. python的代码块缓存机制,小数据池机制。

    同一代码块的缓存机制 在python中一个模块,一个函数,一个类,一个文件等都是一个代码块. 机制内容:Python在执行同一个代码块的初始化对象的命令时,会检查是否其值是否已经存在,如果存在,会将其 ...

  2. 淘系工程师讲解的使用Spring特性优雅书写业务代码

    使用Spring特性优雅书写业务代码   大家在日常业务开发工作中相信多多少少遇到过下面这样的几个场景: 当某一个特定事件或动作发生以后,需要执行很多联动动作,如果串行去执行的话太耗时,如果引入消息中 ...

  3. day06 内存地址 小数据池缓存机制

    1. 内存相关 示例一 v1=[11,22,33] v2=[11,22,33] #值相等 内存地址不等 v1=11 v2=11 #按理说内存地址应该不等,但是python为了优化使其内存地址相等 v1 ...

  4. 小程序的开发框架MINA及小程序的启动机制

    MINA框架分三个部分 视图层(View):有很多页面,每个页面有wxml和wxss组成的,视图结构和展现样式 逻辑层(App Service):处理事物逻辑的地方以及数据交互的服务中心 系统层(Na ...

  5. 【processing】小代码

    今天无意间发现的processing 很有兴趣 实现很简洁 void setup(){ } void draw(){ background(); && mouseY > heig ...

  6. 仅仅需手动添加一行代码就可以让Laravel4执行在SAE (v. 1.0.0)

    Github:https://github.com/chariothy/laravel4-sae (已更新至v1.1.0) laravel4-sae (v. 1.0.0) 仅仅需手动添加一行代码就可以 ...

  7. 小代码编写神器:LINQPad 使用入门

    原文:小代码编写神器:LINQPad 使用入门 一:概述 1:想查看程序运行结果,又不想启动 VS 怎么办? 2:想测试下自己的 C# 能力,不使用 VS 的智能感知,怎么办? 那么,我们有一个选择, ...

  8. Python小代码_2_格式化输出

    Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...

  9. Python小代码_1_九九乘法表

    Python小代码_1_九九乘法表 max_num = 9 row = 1 while row <= max_num: col = 1 while col <= row: print(st ...

随机推荐

  1. FPGA中的时序分析(四)

    常用约束语句说明 关于Fmax      上述是实现Fmax的计算公式,clock skew delay的计算如下图, 就是两个时钟的差值.到头来,影响Fmax的值的大小就是组合逻辑,而Fmax是针对 ...

  2. Github 恶搞教程(一起『玩坏』自己的 Github 吧)

    最近在伯乐在线读到一篇趣文,<如何在 Github『正确』做贡献>,里面各种能人恶搞 Github 的『Public contributions』,下面截取几个小伙伴的战绩: 顺藤摸瓜,发 ...

  3. Flex4/Flash多文件上传(带进度条)实例分享

    要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...

  4. ios开发错误笔记

    今天的奇葩错误,最后解决方式是删除了手机上面的快捷方式,然后再clean,然后再重启了xcode.无语了,xcode也经常出些奇葩问题,真无语啊. ios技术交流群:378501081..期待你加入. ...

  5. 配置Android环境遇到的问题及解决办法

    配置Android环境遇到的问题及解决办法: 1 环境安装地址 http://pan.baidu.com/s/1jGzNzyI 2 其他: 2.1 安装 2.1.1 安装JDK,JRE 成功安装之后, ...

  6. Overcome the Dilemma of "unlock" and "trust"

    When examining an Android phone, we have to overcome some barriers first so that we could extract da ...

  7. py2.7+pyqt4开发端口检测工具

    使用工具:python2.7,pyqt4,pyinstaller,pywin32 先贴代码 import sys from PyQt4 import QtGui,QtCore import threa ...

  8. css3为图片添加鼠标移入放大效果

    只需要为添加效果的图片定义一个伪类 img.zoom-img:hover { -webkit-transform: scale(1.15); -webkit-transition-timing-fun ...

  9. 005windows与Linux文件共享

    基于网络的文件共享: 前提一:从windows能够ping通Linux: 前提二:关闭Linux防火墙,命令[/etc/init.d/iptables stop]: 方法一:通过WinSCP 步骤一: ...

  10. 四、Struts2的执行过程和原理

    执行过程和原理(可能面试题) 学习目标:熟知struts2的执行过程(下图记住).源码可以不看 a.过滤器的初始化 .StrutsPrepareAndExecuteFilter是一个过滤器,过滤器就有 ...