首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
C#中要使一个类支持FOREACH遍历,实现过程怎样?
C#中要使一个类支持FOREACH遍历,实现过程怎样?
admin
2019-03-29
85
问题
C#中要使一个类支持FOREACH遍历,实现过程怎样?
选项
答案
public class DaysOfTheWeek : System.Collections.Ienumerable { string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" }; public System.Collections.IEnumerator GetEnumerator() { for (int i = 0; i < m_Days.Length; i++) { yield return m_Days[i]; } } } class TestDaysOfTheWeek{ static void Main() { // Create an instance of the collection class DaysOfTheWeek week = new DaysOfTheWeek(); // Iterate with foreach foreach (string day in week) { System.Console.Write(day + " "); } }}
解析
转载请注明原文地址:https://kaotiyun.com/show/1RmZ777K
0
程序员面试
相关试题推荐
TheGreeksassumedthatthestructureoflanguagehadsomeconnectionwiththeprocessofthought,whichtookrootinEuropelon
[A]TherelativelylowtuitionfeesinAsiaarealsoamaindrawforprospectivestudents.Lastyear,onlinehighereducationre
[A]Theperson-skillsmatchapproachtoselection[B]Theimpactsofbadselectiondecisions[C]Theimportanceofstructu
输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。 比如将二元查找树转换成双向链表4=6=8=10=12=14=16。
根据委托(delegate)的知识,请完成以下用户控件中代码片段的填写:namespacetest{publicdelegatevoidOnDBOperate();publicclassUserControlBase
设置"考试"文件夹为"只读",并同时应用于所有子文件夹和文件。
在WindowsXP的桌面上打开"回收站"的窗口。
利用D盘窗口,查看WindowsXP已经注册的文件类型,找到"Flash影片"类型。
Excel2000中,列标()A.可以用各种符号表示B.用数字表示C.用字母表示D.可以用中文文字表示
在foxpro中定义数据库结构时,字段名的宽度最多可以是()。A.2B.4C.10D.16
随机试题
凸轮机构中使用平底从动件,其运动规律受到一定限制。()
下列疾病均表现为干性咳嗽,但应除外哪一项疾病
请简述投标报价的算术性错误修正的原则和方法。
沥青混合料中掺加的矿物纤维稳定剂宜采用()制造。
关于证券交易所的普通会员,下列说法正确的是()。
抵押权与其担保的债权同时存在,债权消失的,抵押权也消失。()
被习近平总书记称为“共产党人精神上的‘钙’”的是()。
Theword"aborigines"mostprobablymeans______.Whichofthefollowingpeoplesstillhasitstraditionalwayoflife?
ItisaquestionthathasvexedphilosopherssincetheGreeks.Butitseemswemaynowhavetheanswertothebeguilinglysimple
A、Deathsofsomediseasesdroppedgreatly.B、40-year-oldshavelesslikelihoodtohavehighbloodpressure.C、40-year-oldsarem
最新回复
(
0
)