the foreach in the following C# code works, even if I doesn't do Days:IEnumerable. So this looks like a kind of duck typing. Why is this possible? I thought Days:IEnumerable is obligatory.
using System;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApplication1
{
// works even if I does not
// Days:IEnumerable
public class Days
{
string[] tage = { "mon", "tue", "wed", "thu", "fri" };
public IEnumerator GetEnumerator()
{
for (int i = 0; i < tage.Length; i++)
yield return tage[i];
}
}
class Program
{
static void Main(string[] args)
{
Days daylist = new Days();
foreach (string s in daylist) { Console.WriteLine(s); }
}
}
}