Skip to content

Instantly share code, notes, and snippets.

@skoon
Created July 16, 2009 06:06
Show Gist options
  • Save skoon/148249 to your computer and use it in GitHub Desktop.
Save skoon/148249 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace CodeSamplesForArena.net
{
class Program
{
static void Main(string[] args)
{
var selector = new Selector();
var valueList = new List<Value>();
for (int i = 0; i <= 100; i++)
valueList.Add(new Value { name = "foo" + i, value = i });
var evenList = valueList.Where(x => { return selector.Even(x.value); });
OutputList(x => { Console.WriteLine(x); }, evenList);
Console.ReadKey();
}
public static void OutputList(Action<int> action, IEnumerable<Value> valueList)
{
valueList.Each(x => action(x.value));
}
}
public class Value
{
public int value { get; set; }
public string name { get; set; }
}
public class Selector
{
public Func<int, bool> Even { get { return x => { return (x % 2 == 0); }; } }
}
public static class IEnumerableExtender
{
public static void Each<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var i in source)
action(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment