Datasheet
It’s That Time of Year Again…
x
7
static Program()
{
Instructors.Add(new Instructor(“Al”, “Scherer”, 38,
“Computer Science”));
Instructors.Add(new Instructor(“Albert”, “Einstein”, 50,
“Physics”));
Instructors.Add(new Instructor(“Sigmund”, “Freud”, 50,
“Psychology”));
Instructors.Add(new Instructor(“Aaron”, “Erickson”, 35,
“Underwater Basketweaving”));
Students.Add(new Student(“Matthew”, “Neward”, 10,
“Grade school”));
Students.Add(new Student(“Michael”, “Neward”, 16,
“Video game design”));
Students.Add(new Student(“Charlotte”, “Neward”, 38,
“Psychology”));
Students.Add(new Student(“Ted”, “Neward”, 39,
“Computer Science”));
}
}
Obviously, in a real-world program, these lists of objects will be stored in some form of long-term
storage, such as a relational database, but this suffi ces for now.
IT’S THAT TIME OF YEAR AGAIN…
At the beginning of the school year, new classes are created and entered into the system — again,
this is modeled in the example as a simple list:
List<Class> classesFor2010 = new List<Class>();
classesFor2010.Add(new Class(“Scala for .NET Developers”));
classesFor2010.Add(new Class(“F# for .NET Developers”));
classesFor2010.Add(new Class(
“How to play pranks on teachers”));
classesFor2010.Add(new Class(
“Baskets of the Lower Amazon”));
classesFor2010.Add(new Class(“Child Psych”));
classesFor2010.Add(new Class(“Geek Psych”));
And when the classes have been set up (Instructors will be assigned later, after the Instructors
have determined who is lowest on the totem pole and has to actually teach this year), the students
need to log in to the system and register for classes:
Console.Write(“Please enter your first name:”);
string first = Console.ReadLine();
Console.Write(“\nPlease enter your last name:”);
string last = Console.ReadLine();
After the student has entered this information, the two strings must somehow be reconciled into a
Student object, a process that usually involves searching the list:
foreach (Student s in Students)
{
c01.indd 7c01.indd 7 10/1/2010 3:20:36 PM10/1/2010 3:20:36 PM