黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

对一个List<T>中每一个对象都进行一个函数操作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Person graham
= new Person("Graham", "Hill");
Person emerson
= new Person("Emerson", "Fittipaldi");

List
<Person> Persons = new List<Person>() { graham, emerson };

//对Persons中每个对象都执行Action方法
Persons.ForEach(Action);
}

static void Action(Person p)
{
Console.WriteLine(p.FirstName
+ " " + p.LastName);
}
}

public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }

public Person(string first, string last)
{
FirstName
= first;
LastName
= last;
}
}
}
posted on 2010-05-13 13:59  黄聪  阅读(1189)  评论(3编辑  收藏  举报