• [匿名方法]的用处多(妙用)最新版本


    在上一篇[匿名方法]的用处多(妙用)
    这次发现有更简单的方法ambda表达式
    于是
    下面的这部分代码:
         foreach(Control control in Controls)
        {
               string tmp = listControlType.Find(
                                delegate(string s){
                                        if(s == control.GetType().ToString())
                                                return true;
                                        else
                                                return false;
                                }
                        );

               if(tmp == default(string))
               {
                  listControlType.Add(c.GetType().ToString());
               }
         }

    可以用Lambda改写为:

                    foreach (Control c in Controls)
                    {
                        string tmp = listControlType.Find(s => s == c.GetType().ToString());
                        if(tmp == default(string))
                        {
                                listControlType.Add(c.GetType().ToString());
                                DicControlTypeName.Add(c.Name, c.GetType().ToString());
                                comboBox1.Items.Add(c.GetType().ToString());
                        }
                    }
  • 相关阅读:
    poj 1573 Robot Motion
    poj 1035 Spell checker
    poj 3080 Blue Jeans
    poj 3468 A Simple Problem with Integers(线段树区间更新)
    poj 3687 Labeling Balls(拓补排序)
    poj 3295 Tautology
    poj 1062 昂贵的聘礼
    hdu 1170 Balloon Comes!
    hdu 1215 七夕节
    OCJP-试题集合 | 对象的比较
  • 原文地址:https://www.cnblogs.com/mcjtcnblog/p/1367603.html
Copyright © 2020-2023  润新知