您的位置:首页 > 编程语言 > C#

[转载] C#面向对象设计模式纵横谈——18 Iterator迭代器模式

2012-10-17 08:31 323 查看
主讲:李建忠来源:http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/consyscourse/CsharpOOD.aspx







publicinterfaceIEnumerable
{
IEnumeratorGetEnumerator();
}
publicinterfaceIEnumerator
{
ObjectCurrent{get;}
boolMovenext();
voidReset();
}
privateclassMyEnumerator:IEnumerator
{
intnIndex;
MyCollectioncollection;
publicMyEnumerator(MyCollectioncoll)
{
collection=coll;
nIndex=-1;
}
publicboolMoveNext()
{
nIndex++;
return(nIndex<collection.items.GetLength(0));
}
publicintCurrent
{
get
{
return(collection.items[nIndex]);
}
}
publicvoidReset()
{
nIndex=-1;
}
}

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}









内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: