示例#1
0
        //constructor
        //The job of a constructor is to enusre
        //that all of the fields/properties
        //have "meaningful" values.
        public Program(string[] studentNames)
        {
            WeightedMark[] CourseMarks = new WeightedMark[4];
            CourseMarks[0] = new WeightedMark("Quiz 1", 20);
            CourseMarks[1] = new WeightedMark("Quiz 2", 20);
            CourseMarks[2] = new WeightedMark("Exercises", 25);
            CourseMarks[3] = new WeightedMark("Lab", 35);
            int[] possibleMarks = new int[4] {
                25, 50, 12, 35
            };

            foreach (string name in studentNames)
            {
                EarnedMark[] marks = new EarnedMark[4];
                for (int i = 0; i < possibleMarks.Length; i++)
                {
                    marks[i] = new EarnedMark(CourseMarks[i], possibleMarks[i], 0);
                }
                Students.Add(new Student(name, marks));
            }
        }
示例#2
0
 //Calls another constructer BEFORE it runs its own body of instructions. Hooking up constructors in this fashion is known as "Daisy chaining" your constructor calls
 public EarnedMark(WeightedMark markableItem, int possible, double earned) : this(markableItem.Name, markableItem.Weight, possible, earned)
 {
 }