var one = new List<A>() { new A { Has = true, Name = 1 }, new A { Has = false, Name = 2 }, new A { Has = true, Name = 3 } }; foreach (var item in one) { if (item.Has) { item.Name = 100; } }
one.ForEach(x => { if (x.Has) x.Name = 100; });
很简洁了