Skip to content

Instantly share code, notes, and snippets.

@ungood
Created May 18, 2011 21:42
Show Gist options
  • Select an option

  • Save ungood/979632 to your computer and use it in GitHub Desktop.

Select an option

Save ungood/979632 to your computer and use it in GitHub Desktop.
Example of using IEnumerable as a property
public class Order
{
private List<OrderItem> items = new List<OrderItems>();
public IEnumerable<OrderItem> Items
{
get { return items.Take(int.MaxValue); }
}
}
public class Cheater
{
public void Test()
{
var someOrder = new Order();
// This will no longer work.
((List<OrderItem>)someOrder.Items).Add(new OrderItem());
// This will not (because ToList creates a copy)
someOrder.Items.ToList().Add(new OrderItem());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment