【发布时间】:2023-04-02 21:59:01
【问题描述】:
所以我对 C# OOP 还是很陌生,而且我刚刚在大学里掌握了这种编程风格,并且遇到了数组。现在,我了解了如何创建它们以及它们的一般用途,但我不明白如何使用字符串过滤它们。
对于一个小的背景故事,这是我被要求做的一部分;
在我的部分项目中,我需要创建三个数组,设置主题信息,然后通过显示方法将其输出给用户。我还需要使用 _findExamIndex(根据给定的考试 ID 在考试数组中搜索结果)列出考试,然后使用 _findStudentIndex(在学生列表中搜索学生)来选择个别学生结果。
我遇到的问题是使用字符串 _topicName 过滤 _exams 数组的结果,我不确定如何去做,因为我不熟悉使用数组作为存储数据的方式,并且会非常感谢您的帮助,非常感谢。
(方法代码)
public void viewTopicsResults(string _topicName,List<Results> _results, List<Student> _students, Exam[] _exams, DisplayClass.Display _theDisplay)
{
int[] columnWidths = { 3, 20 };
char[] charactersInTheSpaces = { ' ', ' ' };
string[] topicInfo = new string[6];
topicInfo[0] = "Student";
topicInfo[1] = "Subject";
topicInfo[2] = "Topic";
topicInfo[3] = "Style";
topicInfo[4] = "Date";
topicInfo[5] = "Score";
//Ordering the table by topic.
_theDisplay.writeLineWithTab(topicInfo, columnWidths, charactersInTheSpaces);
foreach(Results result in _results)
{
int examID = _theDisplay.userInputAsInteger("Select a result");
_findExamIndex(examID, _exams);
int studentID = _theDisplay.userInputAsInteger("Please select a users result");
_findStudentIndex(studentID, _students);
//filter on the _exams' Topic == '_topicName'
}
}
(这个方法会被main方法调用)
【问题讨论】:
-
主题是考试的属性,就像考试ID一样?然后看看_findExamIndex的实现。它的解决方式应该有一个很好的资源来说明如何使用 Topic 而不是 ExamID。