曹永思

导航

Lambda表达式遍历和泛型ForEach遍历方式

 

lambda表态式

    DataTable dtAllItems = policySecurity.GetUserAccessTypeOnAllItems(userID);

    List<DataRow> listItemInFunction = (from row in dtAllItems.AsEnumerable()
                                                where row.Field<int>("FunctionID") == functionID
                                                select row).ToList<DataRow>();

泛型遍历,p是一个副本(对于引用类型,是其引用地址的副本),所以对其赋值不影响原值,p = null ,不会改变pluginList中的值

            List<PluginInfo> pluginList = GetSavedState();            
            pluginList.Where(p => p.Enabled == true).ToList().ForEach(delegate(PluginInfo p)
            {
                if (p.ID > 0)
                {
                    //TO DO:
            
            p = null; } });

 

posted on 2017-07-06 09:42  曹永思  阅读(395)  评论(0编辑  收藏  举报