改变类中的一个字段
public ActionResult test() { List<Model> list = new List<Model>() { new Model() { id = 1, name = "aa" }, new Model() { id = 2, name = "bb" } }; var cc = list.Select(delegate(Model a) { a.id = a.id + 1; return a; }); return View(); } public class Model { public int id { get; set; } public string name { get; set; } }
var cc = list.Select(delegate(Model a) { a.id = a.id + 1; return a; }).ToList();
var ff=list;此时list更改后的值,如果不加ToList(),变量list还是原来的值.这点要注意