标签:
List<T> xx = new List<T>();
T x = xx.First(x=>x.x ==x); //寻找对象其中一个匹配值,返回对象
xx.Any(x=> x.x == x); //寻找对象其中一个匹配值,返回bool
using System; using System.Collections.Generic; using System.Linq; namespace rooxml { public class main { public static void Main () { List<A> li = new List<A> (); li.Add (new A(){k=9, v="ddd"}); li.Add (new A(){k=7, v="ddd7"}); li.Add (new A(){k=8, v="ddd55"}); A a = li.First (x => x.k == 7); if (a!=null) { li.Remove (a); Console.WriteLine ("is win"); } foreach(var r in li){ Console.WriteLine (r.v); } Console.WriteLine (); } } class A{ public int k{ get; set;} public string v{ get; set; } } }
标签:
原文地址:http://www.cnblogs.com/nnnnn/p/4463320.html