展开全部
using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace TextTest
{
/// <summary>
/// 学生集合类
/// </summary>
public class Students:Collection<Student>
{
/// <summary>
/// 平均分
/// </summary>
public double AverageScore()
{
return Items.Average(s => s.Score);
}
/// <summary>
/// 最高分
/// </summary>
public int MaxScore()
{
return Items.Max(s => s.Score);
}
/// <summary>
/// 得最高分的第一个学生,MaxScoreStudent.Id就是他的学号
/// </summary>
public Student MaxScoreStudent()
{
int maxScore = MaxScore();
return Items.First(s => s.Score == maxScore);
}
/// <summary>
/// 最大成绩学生的数组序号
/// </summary>
public int MaxScoreStudentId()
{
return Items.IndexOf(MaxScoreStudent());
}
/// <summary>
/// 最低分
/// </summary>
public int MinScore()
{
return Items.Min(s => s.Score);
}
/// <summary>
///得最低分的第一个学生,MinScoreStudent.Id就是他的学号
/// </summary>
public Student MinScoreStudent()
{
int minScore = MinScore();
return Items.First(s => s.Score == minScore);
}
/// <summary>
/// 得最低分的第一个学生的数组序号
/// </summary>
public int MinScoreStudentId()
{
int minScore = MinScore();
return Items.IndexOf(MinScoreStudent());
}
}
/// <summary>
/// 学生类
/// </summary>
public class Student
{
private string _Id;
/// <summary>
/// 学生的学号
/// </summary>
public string Id
{
get { return _Id; }
set { _Id = value; }
}
private int _Score;
/// <summary>
/// 学生的成绩
/// </summary>
public int Score
{
get { return _Score; }
set { _Score = value; }
}
}
}
追问
谢谢啊
展开全部
Main函数:
static void Main(string[] args)
{
Students list = new Students();
list.Add(new Student { Id = "1001", Score = 100 });
list.Add(new Student { Id = "1002", Score = 10 });
list.Add(new Student { Id = "1003", Score = 11 });
list.Add(new Student { Id = "1004", Score = 90 });
list.Add(new Student { Id = "1005", Score = 80 });
list.Add(new Student { Id = "1006", Score = 70 });
list.Add(new Student { Id = "1007", Score = 60 });
list.Add(new Student { Id = "1008", Score = 50 });
list.Add(new Student { Id = "1009", Score = 40 });
list.Add(new Student { Id = "1010", Score = 30 });
Console.WriteLine("最大值是:" + list.MaxScore() + ",最大值下标是:" + list.MaxScoreStudentId());
Console.WriteLine("最小值是:" + list.MinScore() + ",最小值下标是:" + list.MinScoreStudentId());
Console.Read();
}
static void Main(string[] args)
{
Students list = new Students();
list.Add(new Student { Id = "1001", Score = 100 });
list.Add(new Student { Id = "1002", Score = 10 });
list.Add(new Student { Id = "1003", Score = 11 });
list.Add(new Student { Id = "1004", Score = 90 });
list.Add(new Student { Id = "1005", Score = 80 });
list.Add(new Student { Id = "1006", Score = 70 });
list.Add(new Student { Id = "1007", Score = 60 });
list.Add(new Student { Id = "1008", Score = 50 });
list.Add(new Student { Id = "1009", Score = 40 });
list.Add(new Student { Id = "1010", Score = 30 });
Console.WriteLine("最大值是:" + list.MaxScore() + ",最大值下标是:" + list.MaxScoreStudentId());
Console.WriteLine("最小值是:" + list.MinScore() + ",最小值下标是:" + list.MinScoreStudentId());
Console.Read();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询