日期:2014-05-20 浏览次数:20778 次
public class Person { private int _pid; public int Pid { get { return _pid; } set { _pid = value; } } private string _name; public string Name { get { return _name; } set { _name = value; } } private int _age; public int Age { get { return _age; } set { _age = value; } } private string _gender; public string Gender { get { return _gender; } set { _gender = value; } } public Person(){ } public Person(int __pid, string __name, int __age, string __gender) { this._pid = __pid; this._name = __name; this._age = __age; this._gender = __gender; } } List<Person> persons = new List<Person>(); persons.Add(new Person(1, "aaa", 11,"M")); persons.Add(new Person(2, "bbb", 22,"M")); persons.Add(new Person(3, "ccc", 33,"M")); //参数为 谓词(Predicate) //查询所有 年龄>18,性别='M' 的Person对象 List<Person> srcResultList = persons.FindAll(srcCon); Console.WriteLine(srcResultList.Count); //构建查询条件 private static bool srcCon(Person p) { if (p.Age >18 && p.Gender =="M") return true; else return false; }
------解决方案--------------------
哈哈,你好像不是问C#代码,抱歉,我就当自己练习了.
------解决方案--------------------
var stu= from student in stuList
group student by student.Scores.Average() >= 80;
int[] intArray = { 3, 1, 6, 4 };
var stu = intArray.Select(n=>new { Id = n, Name = (stuList as List <Student>)[n].Name });
参考