class Program { static void Main(string[] args) { List<Sales> lsales = new List<Sales>() { new Sales{Num="A01",Performance=198,Score=97}, new Sales{Num="A02",Performance=90,Score=103}, new Sales{Num="A03",Performance=76,Score=78}, new Sales{Num="A04",Performance=123,Score=100}, new Sales{Num="A05",Performance=77,Score=87}, new Sales{Num="A06",Performance=10,Score=54}, new Sales{Num="A07",Performance=81,Score=107}, new Sales{Num="A08",Performance=110,Score=87}, new Sales{Num="A09",Performance=45,Score=41}, new Sales{Num="A10",Performance=123,Score=99}, new Sales{Num="A11",Performance=140,Score=88} }; List<Sales> odsales = new List<Sales>(); foreach (Sales sales in lsales) { if (sales.Performance > lsales.Average(s => s.Performance)) odsales.Add(sales); } odsales.Sort(new performanceCompare()); Console.WriteLine("嗨,留下来:"); foreach (Sales sl in odsales) { Console.WriteLine(sl.Num + " " + sl.Performance + " " + sl.Score); } Console.ReadLine(); } } class Sales { string num;
public string Num { get { return num; } set { num = value; }
} int performance;
public int Performance { get { return performance; } set { performance = value; } } int score;
public int Score { get { return score; } set { score = value; } } } class performanceCompare : IComparer<Sales> { public int Compare(Sales a, Sales b) { return a.Performance.CompareTo(b.Performance); } }
class Program { static void Main(string[] args) { List<Sales> lsales = new List<Sales>() { new Sales{Num="A01",Performance=198,Score=97}, new Sales{Num="A02",Performance=90,Score=103}, new Sales{Num="A03",Performance=76,Score=78}, new Sales{Num="A04",Performance=123,Score=100}, new Sales{Num="A05",Performance=77,Score=87}, new Sales{Num="A06",Performance=10,Score=54}, new Sales{Num="A07",Performance=81,Score=107}, new Sales{Num="A08",Performance=110,Score=87}, new Sales{Num="A09",Performance=45,Score=41}, new Sales{Num="A10",Performance=123,Score=99}, new Sales{Num="A11",Performance=140,Score=88} }; var avr = lsales.Average(s => s.Performance); foreach (var sl in from s in lsales where s.Performance > avr orderby s.Performance descending select s) { Console.WriteLine(sl.Num + " " + sl.Performance + " " + sl.Score); } Console.ReadLine();
}
}
class Sales { string num;
public string Num { get { return num; } set { num = value; } } int performance;
public int Performance { get { return performance; } set { performance = value; } } int score;
public int Score { get { return score; } set { score = value; } }
class Program { static void Main(string[] args) { List<Sales> lsales = new List<Sales>() { new Sales{Num="A01",Performance=198,Score=97}, new Sales{Num="A02",Performance=90,Score=103}, new Sales{Num="A03",Performance=76,Score=78}, new Sales{Num="A04",Performance=123,Score=100}, new Sales{Num="A05",Performance=77,Score=87}, new Sales{Num="A06",Performance=10,Score=54}, new Sales{Num="A07",Performance=81,Score=107}, new Sales{Num="A08",Performance=110,Score=87}, new Sales{Num="A09",Performance=45,Score=41}, new Sales{Num="A10",Performance=123,Score=99}, new Sales{Num="A11",Performance=140,Score=88}
}; var avr = lsales.Average(s => s.Performance); foreach (var sl in from s in lsales where s.Performance > avr orderby s.Performance descending select s) { Console.WriteLine(sl.Num + " " + sl.Performance + " " + sl.Score); } Console.ReadLine();
}
}
class Sales { string num;
public string Num { get { return num; } set { num = value; } } int performance;
public int Performance { get { return performance; } set { performance = value; } } int score;
public int Score { get { return score; } set { score = value; } } }
var avr = lsales.Average(a=>a.Performance); foreach (Sales item in lsales.Where(s => s.Performance > avr).OrderByDescending(s=>s.Performance)) { MessageBox.Show(item.Num); } 我还是觉得我这个看起来舒服一点 [解决办法]
class Program { static void Main(string[] args) { List<Sales> lsales = new List<Sales>() { new Sales{Num="A01",Performance=198,Score=97}, new Sales{Num="A02",Performance=90,Score=103}, new Sales{Num="A03",Performance=76,Score=78}, new Sales{Num="A04",Performance=123,Score=100}, new Sales{Num="A05",Performance=77,Score=87}, new Sales{Num="A06",Performance=10,Score=54}, new Sales{Num="A07",Performance=81,Score=107}, new Sales{Num="A08",Performance=110,Score=87}, new Sales{Num="A09",Performance=45,Score=41}, new Sales{Num="A10",Performance=123,Score=99}, new Sales{Num="A11",Performance=140,Score=88} }; var avr = lsales.Average(s => s.Performance); foreach (var sl in from s in lsales where s.Performance > avr orderby s.Performance descending select s) { Console.WriteLine(sl.Num + " " + sl.Performance + " " + sl.Score); } Console.ReadLine();
}
}
class Sales { string num;
public string Num { get { return num; } set { num = value; } } int performance;
public int Performance { get { return performance; } set { performance = value; } } int score;
public int Score { get { return score; }
set { score = value; } } }
var avr = lsales.Average(a=>a.Performance); foreach (Sales item in lsales.Where(s => s.Performance > avr).OrderByDescending(s=>s.Performance)) { MessageBox.Show(item.Num); } 我还是觉得我这个看起来舒服一点