在c#中解析和转动学生作业数据

时间:2010-10-19 22:06:57

标签: c# arrays list dictionary

我有一个学生/作业对的列表,通过平面文件进入我的应用程序到List对象,我想根据作业列表验证这些作业名称我必须看哪个学生做了什么作业(如果有的话)。

所以 - 我有一个学生列表,学生/作业对列表以及作业列表。

我想创建如下输出:

1. (Heading) -- Student Name -- Assignent One -- Assignment TWo
2. (Detail)  -- John Smith   --  <complete>   -- <complete>

我该如何做到这一点?

到目前为止我所拥有的:     // HACCStudentBlogs将学生列表存储在一个词典中,我一直在追踪每个找到的博客的关键值(粗略,我知道)     //

Dictionary<string, string> studentBlogs = new Dictionary<string, string>();
            foreach (JObject o in root)
            {
                createDate = (string)o["createdDate"];
                studentName = (string)d[(string)o["contributorName"]];
                submittedStudents.Add(studentName);
                title=(string)o["title"];

                    if (HACCstudentBlogs.ContainsKey(studentName))
                    {

                        HACCstudentBlogs[studentName] += "\t" + title.ToUpper();
                    }
                    else
                    {



                    }




            }

2 个答案:

答案 0 :(得分:1)

  1. 由于每个学生需要一行,因此最简单的方法是循环学生列表并为每个学生做点什么。

  2. 在这种情况下,“某事”意味着我们需要组装一行输出。

  3. 每行输出都将包含学生的信息,然后每个作业需要一个部分。因此,在学生的循环中,将会有一个循环超过作业。

  4. 在分配的循环中,我们需要查看并查看是否有一对该学生和作业。如果是这样,我们吐出“完整”。否则,“不完整。”

  5. 所以构建程序的合理方式是这样的:

    // print some header information
    foreach (var student in studentList)
    {
        Display(student.Name);
        foreach (var assignment in assignmentList)
        {
           if (Exists(student, assignment, studentAssignmentPairs))
               Display("<complete>");
           else
               Display("<incomplete>");
        }
        // newline
    }
    

    有一些额外的风格可以很好地格式化它。

    足够开始吗?

答案 1 :(得分:0)

我们真的需要知道列表对象是什么样的

但使用foreach而不是Linq .Distint()woudld是一个很好的开始点