Posts

Showing posts from May, 2011

C# Functional programming

namespace Test { publicstaticclass Extensions { //ForEach IEnumerable extensionpublicstaticvoid ForEach<T>(this IEnumerable<T> source, Action<T> action) { foreach (var item in source) { action(item); } } } class Person { publicstring Name { get; set; } publicstring City { get; set; } } class Account { publicstring Name { get; set; } publicstring AccountName { get; set; } publicdouble Amount { get; set; } public List<string> Cards { get; set; } } [TestFixture] publicclass TestFunc { private List<Person> people; private List<Account> accounts; [TestFixtureSetUp] publicvoid SetUp() { people = new List<Person>(); people.Add(new Person(){Name="John", City="NY"}); people.Add(new Person() { Name = "Tom", City = "London" }); accounts = new List<Account>(); …