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. 转——Android测试之monkey

    一.为什么要用Monkey 测试?   简单在说就是象猴子一样乱点,为了测试软件的稳定性,健壮性.号称最快速有效的方法.有时候运行相同系列的测试,即使是复杂的测试,但是以相同的顺序和路径,即使一遍又一 ...

  2. 前台页面验证中需要注意的一个与VARCHAR2(N BYTE)和VARCHAR2(N CHAR)的小细节

    1:一个小的测试实例 CREATE TABLE SALES.TEST_ ( TEST_BYTE BYTE), TEST_CHAR CHAR) )--TABLE CREATED ')--1 ROW IN ...

  3. mysql中data_format用法

    date_format(date,format)可以把日期转换为制定的格式: mysql> select date_format('2008-08-08 22:23:00', '%W %M %Y ...

  4. 学习资料 50个常用的sql语句

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...

  5. Ov

  6. SQL Server 数据库安全

    --创建登陆用户 --create login login_name from windows with default_database = database | default_language ...

  7. 第九周java学习总结

    20145306<java程序设计>第九周学习总结 教材学习内容总结 第十六章 一.JDBC入门 1.JDBC简介 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据 ...

  8. Mybatis多条件查询

    在Mybatis多条件查询中: 1.参数如果是多条件,则需要将将添加到Map集合中进行传入. 2.就是将其参数用有序数字进行代替. Mybatis单个String类型参数传递 mysql文如下,传入参 ...

  9. GET POST 区别详解

    Get是用来从服务器上获得数据,而Post是用来向服务器上传递数据. 2. Get将表单中数据的按照variable=value的形式,添加到action所指向的URL后面,并且两者使用“?”连接,而 ...

  10. sed的惯常用法

    1:注释掉某一行这个经常会遇到的,把配置文件里某一行注释掉.让他不起作用.sed -i -e ’121 s/^/#/’ /usr/local/apache2/conf/httpd.conf上面一行命令 ...