Skip to content

Instantly share code, notes, and snippets.

@rofr
Last active December 24, 2015 08:39
Show Gist options
  • Save rofr/6772234 to your computer and use it in GitHub Desktop.
Save rofr/6772234 to your computer and use it in GitHub Desktop.
Some immutability stuff for informatorbloggen
public class ImmutableList<T> : IEnumerable<T>
{
List<T> _items;
public ImmutableList()
{
_items = new List<T>();
}
private ImmutableList(List<T> items)
{
_items = items;
}
public ImmutableList<T> Add(T item)
{
var newItems = _items.ToList();
newItems.Add(item);
return new ImmutableList<T>(newItems);
}
public int Count{get{return _items.Count;}}
public IEnumerator<T> GetEnumerator()
{
foreach(T item in _items) yield return item;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment