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. redis学习(3)redis.conf配置文件详解

    # Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k =>  1000 bytes # 1kb ...

  2. Microsoft Visual C++ 2010(86) Redistributable不能安装完美解决

    见http://jingyan.baidu.com/article/9c69d48f41aa6313c9024ebe.html 1. 去mircosoft下载安装包(vcredist_x64.exe) ...

  3. java map缓存

    /**  * 缓存池  * @author xiaoquan  * @create 2015年3月13日 上午10:32:13  * @see  */ public class CachePool { ...

  4. JavaScript基本用法

    首次创建 $(document).ready(function () { });

  5. Oracle笔记 十、PL/SQL存储过程

    --create or replace 创建或替换,如果存在就替换,不存在就创建 create or replace procedure p is cursor c is select * from ...

  6. [转]常用电器认证标志 && 手机频段

    一个手电筒就可以算得上一件家用电器的时代已经过去了,现在,谁家里不得有个几件?大家肯定看到了这些电器上贴的各种各样的认证标志了吧?看的人是眼花缭乱,目不暇接,更有一些是“洋认证”.下面罗列出一些常见的 ...

  7. CSS3 图片悬浮缩放效果

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  8. linux下vi的复制,黏贴,删除,撤销,跳转等命令

    前言     在嵌入式linux开发中,进行需要修改一下配置文件之类的,必须使用vi,因此,熟悉 vi 的一些基本操作,有助于提高工作效率. 一,模式vi编辑器有3种模式:命令模式.输入模式.末行模式 ...

  9. c#使用DocX添加多级标题

    博客转移到 http://jacean.github.io/ 继续分享编程经验 先上效果.可以生成多级标题,但是不能生成1,1.1,1.2这样的自动序列, 只是这样的效果. 实现方法是给Paragra ...

  10. MongoDb 与 Nodejs服务器的启动

    1) 启动MongoDB : MongoDB —dbpath databaseNameFolder. 2) 启动数据库 : Mongo DatabaseName. 3) 启动NodeJs: Node ...