改变类中的一个字段

 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还是原来的值.这点要注意

posted @ 2012-10-24 17:36  pantherbean  阅读(187)  评论(0编辑  收藏  举报