写多线程而又要跨线程处理界面的时候,很郁闷,至少要定义一个delegate,一个函数。用来invoke。如果在new Thread那儿不用匿名函数。还得声明一个函数。郁闷。如果一个线程中多次多种情况处理界面,又不能共用同一delegate,那没法,不得不再定义几个函数、delegate。

        dotnet中还有很多这样的情况,许多方法的参数为delegate/Delegate。lamda解决了这种问题。不要写委托了,因为3.5定义了8个比较常用的delegate:Action<xxxx……,Fun<xxxxx……。不用再写函数。因为lamda就是一种简写的匿名函数。两步都省了。

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<Person> list = new List<Person> { new Person {Name="刘艳涓",Age=27,Sex=true,Address="龙步街" },
                                                  new Person {Name="刘嫦娥",Age=24,Sex=false,Address="龙步街" },
                                                  new Person {Name="钟匀",Age=23,Sex=false,Address="龙步街" },
                                                  new Person {Name="任我行",Age=67,Sex=true,Address="黑木崖"},
                                                  new Person {Name="任盈盈",Age=32,Sex=false ,Address="坐忘峰"}};

            var a = list.FindAll(m => m.Sexs);

            foreach (var b in a)
                System.Diagnostics.Debug.Print(b.ToString());
        }

    }


    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public bool Sex { get; set; }
        public string Address { get; set; }

        public override string ToString()
        {
            return string.Format("姓名:{0},年龄:{1},性别:{2},地址:{3}", this.Name, this.Age, this.Sex ? "男" : "女", this.Address);
        }
    }

posted on 2010-08-19 14:36  异样的世界  阅读(2921)  评论(1编辑  收藏  举报