首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
C#中要使一个类支持FOREACH遍历,实现过程怎样?
C#中要使一个类支持FOREACH遍历,实现过程怎样?
admin
2019-03-29
128
问题
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://www.kaotiyun.com/show/1RmZ777K
0
程序员面试
相关试题推荐
Signslike"Pleaseratemefivestars"pointtoagrowingproblemwithbusinessesintheon-demandeconomyofapp-basedservices
[A]Theperson-skillsmatchapproachtoselection[B]Theimpactsofbadselectiondecisions[C]Theimportanceofstructu
Individualsandbusinesseshavelegalprotectionforintellectualpropertytheycreateandown.Intellectualproper【C1】______fro
Asthelatestcropofstudentspentheirundergraduateapplicationformandweighuptheiroptions,itmaybeworthconsidering
求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。句子中单词以空格符隔开。为简单起见,标点符号和普通字母一样处理。例如输入“Iamastudent.”,则输出“student.aamI”。
存储过程和函数的区别
利用快捷菜单将桌面上的图标按“类型”排列。
Dreamweaver的编辑(Edit)菜单命令中,SelectAll表示______。A.将剪贴板拷贝至当前光标位置B.从文档中删除当前选区C.选取当前文档中所有元素D.使用HTML代码将当前选区拷贝到剪贴板
随机试题
司法机关对乡、镇人大代表采用取保候审,需事先取得该级人民代表大会许可。
Justletitgo______youdon’twanttobeinvolvedinanyargument.
金黄色葡萄球菌感染常可引起
物体作定轴转动的转动方程为φ=4t一3t2(φ以rad计,t以s计)。此物体内,转动半径r=0.5m的一点,在t0=0时的速度和法向加速度的大小为()。
已知年利率12%,每月复利计息一次,则季实际利率为()。
单位为了提高工作效率,要你组织一个“强责任,提警力”的主题思想教育活动,有老同志认为这种活动是形式主义,非常不支持,对此你将如何与他沟通?请把主考官当作是这个同志,进行一下现场模拟。
以下程序从终端读入数据到数组中,统计其中正数的个数,并计算它们之和,请填空。#include<stdio,h>main()inti,a[20],sum,count;
What’sKategoodat?
OneofthecontributionsofTheodoreRooseveltaspresidentwas______.
Forauthorsofself-helpguides,nohumanproblemistoogreatortoosmall.Wanttobecomefitter,richerorhappierin2015?T
最新回复
(
0
)