输
对一个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;
}
}
}
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;
}
}
}
作者:黄聪
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。