コード例 #1
0
        private void makeStudents()
        {
            Student firstStudent = new Student();
            Student.StudentCount++;
            Student secondStudent = new Student();
            Student.StudentCount++;
            Student thirdStudent = new Student("Peter", "String", "80%");
            Student.StudentCount++;

            firstStudent.firstName = "John";
            firstStudent.lastName = "Smith";
            firstStudent.grade = "six";

            secondStudent.firstName = "Tom";
            secondStudent.lastName = "Thumb";
            secondStudent.grade = "two";

            Console.WriteLine("firstStudent.firstName = " + firstStudent.firstName);
            Console.WriteLine("secondStudent.firstName = " + secondStudent.firstName);
            Console.WriteLine("thirdStudent.firstName = " + thirdStudent.firstName);
            Console.WriteLine("Student.StudentCount = " + Student.StudentCount);

            Program.dividingLine();

            firstStudent.displayName();
            Console.WriteLine(secondStudent.concatenateName());

            //pass reference type - method will affect the instance passed to it
            changeStudent(firstStudent);
            Console.WriteLine("Now firstStudent fullname = " + firstStudent.concatenateName());
        }
コード例 #2
0
 private void changeStudent(Student inStudent)
 {
     //because student is a reference type changes made in this method will change the student at Program level
     inStudent.lastName = "Self";
 }