using System.Collections;
using System.Collections.Generic;
public static void Main()
public static IEnumerable<int> GetFoos()
using (var fooSource = new DisposableFoo())
return fooSource.GetFoos();
public static IEnumerable<int> GetFoosWithForeach()
using (var fooSource = new DisposableFoo())
foreach (var foo in fooSource.GetFoos())
public class DisposableFoo : IDisposable
public bool Disposed { get; set; }
GC.SuppressFinalize(this);
protected virtual void Dispose(bool disposing)
public IEnumerable<int> GetFoos()
throw new ObjectDisposedException("");