using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;namespace ddq1
{
public class DaysOfTheWeek : System.Collections.IEnumerable
{
string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" }; public IEnumerator GetEnumerator()
{
for (int i = 0; i < m_Days.Length; i++)
{
yield return m_Days[i];
}
}
} class TestDaysOfTheWeek
{
static void Main()
{
DaysOfTheWeek week = new DaysOfTheWeek();
foreach (string day in week)
{
System.Console.Write(day + " ");
}
Console.Read();
}
}}在程序中 public IEnumerator GetEnumerator() 是实现IEnumerable接口, 而我发现在程序中没加 : IEnumerable 接口申明怎么也能编译通过?
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;namespace ddq1
{
public class DaysOfTheWeek : System.Collections.IEnumerable
{
string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" }; public IEnumerator GetEnumerator()
{
for (int i = 0; i < m_Days.Length; i++)
{
yield return m_Days[i];
}
}
} class TestDaysOfTheWeek
{
static void Main()
{
DaysOfTheWeek week = new DaysOfTheWeek();
foreach (string day in week)
{
System.Console.Write(day + " ");
}
Console.Read();
}
}}在程序中 public IEnumerator GetEnumerator() 是实现IEnumerable接口, 而我发现在程序中没加 : IEnumerable 接口申明怎么也能编译通过?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货