手动书写小代码-foreach实现机制
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实现机制的更多相关文章
- python的代码块缓存机制,小数据池机制。
同一代码块的缓存机制 在python中一个模块,一个函数,一个类,一个文件等都是一个代码块. 机制内容:Python在执行同一个代码块的初始化对象的命令时,会检查是否其值是否已经存在,如果存在,会将其 ...
- 淘系工程师讲解的使用Spring特性优雅书写业务代码
使用Spring特性优雅书写业务代码 大家在日常业务开发工作中相信多多少少遇到过下面这样的几个场景: 当某一个特定事件或动作发生以后,需要执行很多联动动作,如果串行去执行的话太耗时,如果引入消息中 ...
- day06 内存地址 小数据池缓存机制
1. 内存相关 示例一 v1=[11,22,33] v2=[11,22,33] #值相等 内存地址不等 v1=11 v2=11 #按理说内存地址应该不等,但是python为了优化使其内存地址相等 v1 ...
- 小程序的开发框架MINA及小程序的启动机制
MINA框架分三个部分 视图层(View):有很多页面,每个页面有wxml和wxss组成的,视图结构和展现样式 逻辑层(App Service):处理事物逻辑的地方以及数据交互的服务中心 系统层(Na ...
- 【processing】小代码
今天无意间发现的processing 很有兴趣 实现很简洁 void setup(){ } void draw(){ background(); && mouseY > heig ...
- 仅仅需手动添加一行代码就可以让Laravel4执行在SAE (v. 1.0.0)
Github:https://github.com/chariothy/laravel4-sae (已更新至v1.1.0) laravel4-sae (v. 1.0.0) 仅仅需手动添加一行代码就可以 ...
- 小代码编写神器:LINQPad 使用入门
原文:小代码编写神器:LINQPad 使用入门 一:概述 1:想查看程序运行结果,又不想启动 VS 怎么办? 2:想测试下自己的 C# 能力,不使用 VS 的智能感知,怎么办? 那么,我们有一个选择, ...
- Python小代码_2_格式化输出
Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...
- Python小代码_1_九九乘法表
Python小代码_1_九九乘法表 max_num = 9 row = 1 while row <= max_num: col = 1 while col <= row: print(st ...
随机推荐
- 长期内部推荐SAP职位,包括Java ABAP 咨询顾问,Developer,架构师等。
长期内部推荐SAP职位,包括Java ABAP 咨询顾问,Developer,架构师等. 有需要请发简历到邮箱 LoB Position LocationAcquisitions Hybris ...
- 【转载】Myeclipse如何自动创建hibernate
Myeclipse如何自动创建hibernate:http://jingyan.baidu.com/article/456c463b99f4370a583144a8.html An internal ...
- Flex 三态复选框
在周末挤出了一点时间,写了一个三态复选框的组件,单独使用没有价值,不过集成到树之中可以很好的实现三态树,今天上午便把三态树组件也完成了,Flex自定义组件基本无所不能,此组件基于最新的Flex4.6( ...
- springMVC导出 CSV案例
导出csv 第一步 Controller类里调用 OrderParamsVo 传入的参数 orderService.findBuyCSV 查询到要导出的信息 /** * 购买订单CSV * Order ...
- linux下的mysql乱码问题
1,承接上一随笔,因为我用的是rmp的两种反式. rpm -ivh MySQL-server-4.0.14-0.i386.rpm rpm -ivh MySQL-client-4.0.14-0.i386 ...
- DEDE的data目录名称修改方法
DEDE的data目录名称修改方法 为了最大限度的减少网站被攻击的可能,需要将data目录改名,具体操作如下: 1.修改include目录下的common.inc.php这个文件.打开文件,找到第16 ...
- libpcap报文解析: ipv4、ipv6 @ 2014.7.2
#include <string.h> #include <stdlib.h> #include <pcap.h> #include <stdio.h> ...
- Facebook React完全解析
2004年,对于前端社区来说,是里程碑式的一年.Gmail横空出世,它带来基于前端渲染的原生应用级别的体验,相对于之前的服务端渲染网页可谓提升了一个时代,触动了用户的G点.自此,前端渲染的网站成为无数 ...
- Java Excel POI
1.使用 String toFileName = "E:\\sheet1.xlsx"; String fromFileName = "E:\\sheet2.xlsx&qu ...
- 单例模式(Winform窗体的实现)
在我的设计模式分类当中,我选择单例模式作为我第一个要写的设计模式,其一,单例模式简单.容易理解让人接受,其二,单例模式很常用,在实际的Winform窗体应用开发中能够带来更好的客户体验. 单例模式的核 ...