麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

IEnumerable、GetEnumerator、IEnumerator之間的關系。

2019-11-14 16:44:26
字體:
來源:轉載
供稿:網友
了解了這些也就明白了遍歷的原理,晚安。

  1 using System;  2 using System.Collections;  3   4 public class Person  5 {  6     public Person(string fName, string lName)  7     {  8         this.firstName = fName;  9         this.lastName = lName; 10     } 11  12     public string firstName; 13     public string lastName; 14 } 15  16 public class People : IEnumerable 17 { 18     PRivate Person[] _people; 19     public People(Person[] pArray) 20     { 21         _people = new Person[pArray.Length]; 22  23         for (int i = 0; i < pArray.Length; i++) 24         { 25             _people[i] = pArray[i]; 26         } 27     } 28  29     IEnumerator IEnumerable.GetEnumerator() 30     { 31        return (IEnumerator) GetEnumerator(); 32     } 33  34     public PeopleEnum GetEnumerator() 35     { 36         return new PeopleEnum(_people); 37     } 38 } 39  40 public class PeopleEnum : IEnumerator 41 { 42     public Person[] _people; 43  44     // Enumerators are positioned before the first element 45     // until the first MoveNext() call. 46     int position = -1; 47  48     public PeopleEnum(Person[] list) 49     { 50         _people = list; 51     } 52  53     public bool MoveNext() 54     { 55         position++; 56         return (position < _people.Length); 57     } 58  59     public void Reset() 60     { 61         position = -1; 62     } 63  64     object IEnumerator.Current 65     { 66         get 67         { 68             return Current; 69         } 70     } 71  72     public Person Current 73     { 74         get 75         { 76             try 77             { 78                 return _people[position]; 79             } 80             catch (IndexOutOfRangeException) 81             { 82                 throw new InvalidOperationException(); 83             } 84         } 85     } 86 } 87  88 class App 89 { 90     static void Main() 91     { 92         Person[] peopleArray = new Person[3] 93         { 94             new Person("John", "Smith"), 95             new Person("Jim", "Johnson"), 96             new Person("Sue", "Rabon"), 97         }; 98  99         People peopleList = new People(peopleArray);100         foreach (Person p in peopleList)101             Console.WriteLine(p.firstName + " " + p.lastName);102 103     }104 }105 106 /* This code produces output similar to the following:107  *108  * John Smith109  * Jim Johnson110  * Sue Rabon111  *112  */

 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 偷偷操偷偷操 | 美女毛片在线观看 | 欧日韩在线视频 | 黄色av.com | 欧美a黄| 手机av免费电影 | 欧美性生视频 | 黄色毛片视频在线观看 | 91成人在线免费观看 | av在线播放地址 | www.狠狠操.com| 欧美在线观看视频一区 | 欧美18一12sex性处hd | 久久婷婷一区二区三区 | 一级做受毛片免费大片 | 毛片在线视频免费观看 | 91av久久| 7777视频| 久久最新免费视频 | 久精品久久 | 欧美一区黄色 | 黄色大片www | 日韩毛片在线看 | 色吧久久 | 国产毛片aaa一区二区三区视频 | 欧美成人午夜 | 国产精品成人一区二区三区吃奶 | 国产精品亚洲综合一区二区三区 | 国产精品一区二区视频 | 久久精品一区二区三区不卡牛牛 | 亚洲五码在线观看视频 | 国产成人羞羞视频在线 | 97黄色网 | 欧美视频一二三区 | 一区二区三区国产视频 | 国产亚洲精品综合一区91555 | 日韩毛片一区二区三区 | xxxⅹ96日本护士hd | 国产1区2区3区中文字幕 | 欧美成人精品不卡视频在线观看 | 久久国产精品区 |