成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

IEnumerable接口

=================================================簡單的實現(xiàn)IEnumerable接口

目前創(chuàng)新互聯(lián)建站已為成百上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、樂亭網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

------------------------------------Person.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApplication6
{
    public class Person
    {
        public string Name { get; set; }
    }
}

------------------------------------PerAll.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApplication6
{
    public class PerAll:IEnumerable
    {
        Person[] p = new Person[3];//實例化長度為三個的數(shù)組
        public PerAll()//構(gòu)造函數(shù)初始化數(shù)組
        {
            p[0] = new Person { Name = "張三" };
            p[1] = new Person { Name = "李四" };
            p[2] = new Person { Name = "王五" };
        }
        public IEnumerator GetEnumerator()//迭代器
        {
            return p.GetEnumerator();//直接調(diào)用數(shù)組自帶的的GetEnumerator。(簡單委托請求到System.Array)
        }
    }
}

------------------------------------主程序

            PerAll p = new PerAll();//實例化對象
            //-------------------第一種方式遍歷
            foreach (Person  item in p)
            {
                Console.WriteLine(item.Name);
            }
            //-------------------第二中方式遍歷
            IEnumerator ie = p.GetEnumerator();
            while (ie.MoveNext())
            {
                Console.WriteLine((ie.Current as Person).Name);
            } 
            
            
            
            //普通數(shù)組遍歷
            string[] str = new string[3] { "張遼", "張合", "張飛" };
            IEnumerator strie = str.GetEnumerator();
            while (strie.MoveNext())
            {
                Console.WriteLine(strie.Current as string);
            }

 

網(wǎng)站名稱:IEnumerable接口
URL地址:http://jinyejixie.com/article18/jjejdp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名網(wǎng)頁設(shè)計公司、自適應(yīng)網(wǎng)站、建站公司、關(guān)鍵詞優(yōu)化、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)
安化县| 政和县| 成武县| 大同县| 永康市| 新竹市| 贺兰县| 大安市| 贵定县| 临朐县| 平利县| 内黄县| 鄱阳县| 宾阳县| 应城市| 衡南县| 桂阳县| 通城县| 光山县| 信丰县| 靖安县| 额尔古纳市| 陆良县| 淮安市| 奈曼旗| 丽江市| 夏津县| 金溪县| 马山县| 鄂托克前旗| 汶上县| 镇巴县| 龙川县| 军事| 蓬溪县| 兴城市| 进贤县| 孟村| 二连浩特市| 柳州市| 南通市|