我的项目中的LINQ问题 [英] linq problem in my project

查看:60
本文介绍了我的项目中的LINQ问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提供的代码文件中定义了两个类.

There are two class defined in the provided code file.

    public class CourseScore
    {
        public string CourseCode { get; set; }
        public int StudentId { get; set; }
        public double Score { get; set; }

        public static List<coursescore> GetScores()
        {
            List<string> courseCodes = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                string code = RandomNumber(1, 5).ToString() + RandomNumber(0, 9).ToString() + RandomNumber(0, 9).ToString();
                courseCodes.Add(code);
            }
            courseCodes = courseCodes.Distinct().ToList();

            List<coursescore> scores = new List<coursescore>();
            for (int i = 0; i < 1000; i++)
            {
                string code = courseCodes[RandomNumber(0, courseCodes.Count - 1)];
                int studentId = RandomNumber(1, 500);
                double degree = RandomNumber(50, 100);
                if (!scores.Any(cs => cs.CourseCode == code && cs.StudentId ==  studentId))
                {
                    scores.Add(new CourseScore(code, studentId, degree));
                }
            }
     
            return scores;
        }
}
        private static Random random = new Random(0);
        private static int RandomNumber(int min, int max)
        {
            return random.Next(min, max);
        }

    public class CourseAverageScore
    {
        public string CourseCode { get; set; }
        public double AverageScore { get; set; }
    }</coursescore></coursescore></string></string></coursescore>



"CourseScore"课程代表数据库表格中有关学生参加课程及其成绩的记录.每个课程都有一个唯一的"CourseCode",每个学生都有一个唯一的"StudentId"编号,"Score"属性是该课程的学生获得的分数.
使用LINQ或Lambda Expression编写一个函数,该函数接受"CourseScore"对象的列表并返回"CourseAverageScore"的集合,并且返回集合中的每个"CourseAverageScore"对象都应代表一门课程,该课程为3级课程(课程代码以"3"开头),并且不少于5名学生参加. "AverageScore"属性应具有该课程的平均成绩值.
此函数应仅包含一个语句,该语句是用于执行所有计算的return语句.该函数将如下所示:



The class ’CourseScore’ represents records in a database table about students taking courses and their scores. Each course has a unique ‘CourseCode’, each student has a unique ‘StudentId’ number, and the ‘Score’ property is the grade the student got for this course.
Use LINQ or Lambda Expression to write a function that takes a list of ‘CourseScore’ objects and return a collection of ‘CourseAverageScore’, and each ‘CourseAverageScore’ object in the return collection should represent a course which is a level-3 course (Course code starts with ‘3’) and is taken by no less than 5 students. The ‘AverageScore’ property should have the value of average grade for that course.
This function should only include one statement which is the return statement to implement all calculations. The function will look like this:

static IEnumerable<courseaveragescore> 
       GetCourseAverageLinq(IEnumerable<coursescore> scoreRecords)
    {
        return …;
    }</coursescore></courseaveragescore>


在类'CourseScore'中使用静态方法'GetScores'获取源数据,并使用控制台应用程序演示此函数的输出.


Use the static method ‘GetScores’ in class ‘CourseScore’ to get the source data and use a Console application to demonstrate the output of this function.

推荐答案

要张贴作业,至少要使其看起来像是您自己尝试做某事!

我们不做您的作业:这是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,或学习魔语:您要用它炸薯条吗?"
If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, or learn the Magic Words: "Do you want fries with that?"


这篇关于我的项目中的LINQ问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆