日期:2014-05-18 浏览次数:20908 次
void Main() { var list=new List<model> { new model{ a=1, b=1.1F,c=1.8F}, new model{ a=2, b=2.2F,c=1.4F}, new model{ a=3, b=3.1F,c=1.6F}, new model{ a=5, b=4.1F,c=1.5F}, new model{ a=7, b=5.1F,c=1.3F}, new model{ a=9, b=7.1F,c=1.7F}, new model{ a=4, b=8.1F,c=1.9F}, new model{ a=11, b=11.1F,c=1.66F}, new model{ a=6, b=12.1F,c=1.22F} }; float[] arr=new float[]{1F,1.2F,1.3F,1.4F,1.5F,1.6F,1.7F,2.2F,3.3F,4.4F,5.5F,6.6F,7.7F}; var query=from a in arr.Select((a,b)=>new{index=b,value=a}) join l in list on a.index equals l.a where a.value>=l.b && a.value<l.c select l; Console.WriteLine("a\tb\tc"); query.ToList().ForEach(q=>Console.WriteLine("{0}\t{1}\t{2}",q.a,q.b,q.c)); /* a b c 1 1.1 1.8 */ } public class model { public int a{get;set;} public float b{get;set;} public float c{get;set;} }
------解决方案--------------------
var s = from m in list where (arr[m.a] >= m.b) && (arr[m.a] <= m.c) select m;