This is all in C#, using .NET 3.5.
I have a list populated with book information. Each item contains the course abbreviation, the course number, and the section of the course:
myList1.Add("ACCT", 100, "1");
myList1.Add("ACCT", 100, "2");
myList1.Add("BUS", 101, "1"); and so on...
What I need to do is combine items that have the same curriculum and course so the sections are in one string.
"ACCT", 100, "1, 2"
"BUS", 101, "1"
How should I go about comparing each item in the list to check for matches? The original method utilized a long chain of if-else statements and used 5 lists. I’m trying to avoid that. Is this question on the right track for me?
EDIT: To answer Philipp’s question, the list uses a class containing those properties like Thomas Levesque’s answer:
class Course
{
public string Abbreviation { get; set; }
public int Number { get; set; }
public string Section { get; set; }
}
And is populated by a method from a DataAccess class:
List<Course> list = DataAccess.GetData();
Hope that clears that up.
Assuming the following class declaration:
You can do something like that: