日期:2014-05-20 浏览次数:21215 次
List<int> lst=new List<int>();
lst.Add(1);
lst.Add(3);
lst.Add(5);
lst.Add(7);
//希望执行以下修改:如果整数大于3,则将整数增加10,否则保持不变。
lst.ForEach(c=>c=c>3?c+10);
//得到的结果期望是lst的元素值:1,3,15,17
List<int> lst = new List<int>();
lst.Add(1);
lst.Add(3);
lst.Add(5);
lst.Add(7);
//希望执行以下修改:如果整数大于3,则将整数增加10,否则保持不变。
//lst.ForEach(c=>c=c>3?c+10);
//得到的结果期望是lst的元素值:1,3,15,17
List<int> lstTemp = new List<int>();
lst.ForEach(delegate(int argInt)
{
if (argInt > 3)
lstTemp.Add(10 + argInt);
else
lstTemp.Add(argInt);
});