The bottom line is that I learn every day and .NET doesn't stop surprising me which is fun :).
EDIT: I've modified the image because it looked horrible.
using System; using System.Collections.Generic; using System.Text; using System.Collections; class Program { static void Main(string[] args) { FakeEnumerableClass enumerable = new FakeEnumerableClass(); foreach (object o in enumerable) { //works perfectly fine :) } } } class FakeEnumerableClass { public FakeEnumerator GetEnumerator() { return new FakeEnumerator(); } } public class FakeEnumerator { public bool MoveNext() { return false; } public object Current { get { return null; } } } class RealEnumberableClass : IEnumerable { public IEnumerator GetEnumerator() { throw new Exception("The method or operation is not implemented."); } }
No comments:
Post a Comment