zoukankan
html css js c++ java
IEnumerable 和 IEnumerator 接口
实现IEnumerable接口的类,可以支持foreach循环遍历对象的集合元素
IEnumerable:
IEnumerator
GetEnumerator()
返回可循环访问集合的枚举数。
IEnumerator:
object
Current
获取集合中的当前元素。
bool
MoveNext()
将枚举数推进到集合的下一个元素。
如果枚举数成功地推进到下一个元素,则为
true
;如果枚举数越过集合的结尾,则为
false
。
void
Reset()
将枚举数设置为其初始位置,该位置位于集合中第一个元素之前。
sample:
using
System;
using
System.Collections;
namespace
ConsoleApplication1
{
/**/
///
<summary>
///
Summary description for Class1.
///
</summary>
class
Class1
{
/**/
///
<summary>
///
The main entry point for the application.
///
</summary>
[STAThread]
static
void
Main(
string
[] args)
{
CStringEnum se
=
new
CStringEnum();
foreach
(
string
s
in
se)
{
Console.WriteLine(s);
}
Console.Read() ;
}
}
class
CStringEnum : IEnumerable, IEnumerator
{
string
[] items
=
new
string
[
16
];
int
index
=
-
1
;
public
CStringEnum()
{
for
(
int
i
=
0
; i
<
items.Length;
++
i)
items[i]
=
"
s
"
+
i.ToString();
}
IEnumerable Members
#region
IEnumerable Members
public
IEnumerator GetEnumerator()
{
//
TODO: Add StringCollection.GetEnumerator implementation
return
(IEnumerator)
this
;
}
#endregion
IEnumerator Members
#region
IEnumerator Members
public
void
Reset()
{
//
TODO: Add CStringEnum.Reset implementation
index
=
-
1
;
}
public
object
Current
{
get
{
//
TODO: Add CStringEnum.Current getter implementation
return
items[index];
}
}
public
bool
MoveNext()
{
//
TODO: Add CStringEnum.MoveNext implementation
index
++
;
return
index
>=
items.Length
?
false
:
true
;
}
#endregion
}
}
查看全文
相关阅读:
多线程,死锁,DeadLock
多线程,Socket,上传文件
MyBatis自动创建代码
oracle 11g 监听启动成功后立马自动关闭
echart 报表图片不展示
quick easyui ftp 启动报错,bind port faild,maybe another……
jquery.easyui.min.js:1 Uncaught TypeError: $.fn.validatebox.methods[_43e] is not a function(…)
无效的列类型
当eclipse发送报文乱码时,在java代码中发送和接收的地方都改成utf-8编码即可
ie js new date
原文地址:https://www.cnblogs.com/xgw2004058/p/1756778.html
最新文章
安装cuda配置环境变量
进化算法
计算机三级网络技术知识点
自学C++写的一个简单贪吃小河游戏
各算法理解
基偶转换排序
算法分析考试
解决w10与ubuntu18.04时间不同步问题
ubuntu时间改变
4.python基础语法--input()函数
热门文章
3.python基础语法--分支语句
2.python基础语法--垃圾回收
gitosis clone项目时需要密码,全路径 解决办法
VMware Kernel Module Updater
Hibernate重点
struts2登陆拦截器 (FIX)
struts2使用response和request功能
struts2动作方法通配符
struts2自定义结果类型
单例设计模式
Copyright © 2011-2022 走看看