class T
{ public int Key; pubic List<int> ints ;//长度可变
}
///// List<T> list = new List<T>();
要求:根据用户输入的字符串值得到结果 如 select * from list where ints[0]>10 && ints[0] <20 && ints[500] >9 && ints[500] <100 order by Key desc 输出满足条件的对象
{ public int Key; pubic List<int> ints ;//长度可变
}
///// List<T> list = new List<T>();
要求:根据用户输入的字符串值得到结果 如 select * from list where ints[0]>10 && ints[0] <20 && ints[500] >9 && ints[500] <100 order by Key desc 输出满足条件的对象
where l.ints[0]>10 && l.ints[0] <20 && l.ints[500] >9 && l.ints[500] <100
order by Key descending
select ;
where l.ints[0]>10 && l.ints[0] <20 && l.ints[500] >9 && l.ints[500] <100
order by Key descending
select l;
// 以这条为准:
var query= from l in list
where l.ints[0]>10 && l.ints[0] <20 && l.ints[500] >9 && l.ints[500] <100
order by l.Key descending
select l;
//也可以这么写:
var query= list.Where(l=>l.ints[0]>10 && l.ints[0] <20 && l.ints[500] >9 && l.ints[500] <100).OrderByDescending(l=>l.Key);
{
List<item> list=new List<item>();
//for添加item到list
Random random = new Random();
for (int i = 0; i < 30; i++)
{
item ii = new item();
ii.Key = random.Next(0, 600);
for (int j = 0; j < ii.Key; j++)
{
ii.ints.Add(random.Next(0,50));
}
list.Add(ii);
}
list.Sort(new MyComparer());//利用iComparer接口排序 List<item> ret = list.FindAll(new Predicate<item>(select));//查询结果
}
bool select(item ii)
{
if (ii.ints.Count == 0|ii.ints.Count<500)
return false;
if (ii.ints[0] > 10 && ii.ints[0] < 20 && ii.ints[500] > 9 && ii.ints[500] < 100)
return true;
return false; }
}
class item
{
public int Key;
public List<int> ints=new List<int>();//长度可变
}
class MyComparer : IComparer<item>
{
int IComparer<item>.Compare(item x, item y)
{
return x.Key > y.Key ? -1 : 1;
}
}至于怎么输入字符串自己改改吧