Wednesday, May 11, 2011

Generic with Lamda Expression

public void Each(IEnumerable items, Action action)
{
foreach (var item in items)
{
action(item);
}
}

public void Main()
{
List myList = new List();
myList.Add(1);
myList.Add(3);

Each(myList, i => textBox1.AppendText(i.ToString()+ "\r\n") );

new List(myList).ForEach(i => textBox1.AppendText(i.ToString() + "\r\n"));

}

No comments:

Post a Comment