首页 > 代码库 > foreach 、 for 换成 ForEach

foreach 、 for 换成 ForEach

 List<tBaseRolerMapPower> list =new  List<tBaseRolerMapPower>()

 string strName = string.Empty;
  foreach (tBaseRolerMapPower item in list)
  {
      strName += item.power_name + ",";
  }


 换成:

 list.ForEach(p =>
                    {
                        strName = strName + p.power_name + ",";
                    });

 

说白了  foreach (tBaseRolerMapPower item in list)  等于 ForEach(p => 以下{}中的东西都一样

foreach 、 for 换成 ForEach