第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

C#的IEumerable的用法

C#的IEumerable的用法

C#
Besthope 2016-10-18 20:43:55
using?System; using?System.Collections.Generic; namespace?yield_return { ????class?Program ????{ ????????static?List<int>?GetData() ????????{ ????????????return?new?List<int>?{3,2,1,4}; ????????} ????????static?IEnumerable<int>?List() ????????{ ????????????foreach?(int?i?in?GetData()) ????????????{ ????????????????if?(i?>?2) ????????????????{ ????????????????????yield?return?i; ????????????????} ????????????????yield?break; ????????????} ????????} ????????static?void?Main(string[]?args) ????????{ ????????????foreach?(var?item?in?List()) ????????????{ ????????????????Console.Write(item); ????????????} ????????} ????} }為什么要使用IEumerable這樣寫不如寫成數(shù)組:using?System; class?Program?{ ????static?int[]?myarr?=?new?int[]?{?1,?2,?3?}; ????static?void?Method() ????{ ????????foreach?(int?i?in?myarr) ????????{ ????????????if?(i?>?2) ????????????{ ????????????????Console.Write(i); ????????????} ????????} ????} ????static?void?Main(string[]?args) ????{ ????????Method(); ????} }
查看完整描述

1 回答

?
一毛錢

TA貢獻(xiàn)156條經(jīng)驗(yàn) 獲得超57個(gè)贊

IEumerable 是接口,數(shù)組類的都繼承與他,你這樣寫也是可以的,就像所有的類型都繼承與Object一樣,你可以定義int a=0; 也可以寫成object a=0;

查看完整回答
反對(duì) 回復(fù) 2016-10-20
  • 1 回答
  • 0 關(guān)注
  • 1641 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)