经验36--C#无名(大事,物...)

有时候,方便代码,它会使用匿名的东西。

1、匿名事件

args.CookieGot += (s, e) =>
                {
                    this.IsWebLogon = true;
                };

不用专门再去写方法,当然这样的方式简单介绍的时候使用。

2、匿名对象

var ohList = ohManager.GetList().Select(x => new { x.ID, x.Name,x.CreateTime });

用户接口或前后台交互,指定某些字段,且新的对象,不用再去建实体。

3、匿名Form线程

this.Invoke(new Action(() =>
            {
                Btc38ImageForm form = new Btc38ImageForm();
                form.ShowDialog();
            }));

防止影响主form。不会卡。

4、匿名线程

Thread t = new Thread(() =>
            {
                Runing();
            });
            t.IsBackground = true;//程序关闭。线程关闭
            t.Start();

5、匿名timer

timer = new System.Timers.Timer(1 * 1000);
                timer.Elapsed += (s, e) => {
                    d1.Runing();
                    d15.Runing();
                };
                timer.AutoReset = true;
                timer.Enabled = true;
                timer.Start();

分类似匿名事件。

版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-10-16 20:36  phlsheji  阅读(138)  评论(0编辑  收藏  举报