コード例 #1
0
        public void PassingObjectsToMethods()
        {
            Student2 student = new Student2("Vijay Gawade", 22, "Matond");

            Console.WriteLine("Before:\t\tName:{0}\tAge:{1}\tAddress:{2}", student.Name, student.Age, student.Address);
            // Note Class Object always pass by Refference, so any change in obj into method will reflect here also
            // When you pass an object to a method, the object is passed by reference
            IncrementStudentAge(student);
            Console.WriteLine("After:\t\tName:{0}\tAge:{1}\tAddress:{2}", student.Name, student.Age, student.Address);
        }
コード例 #2
0
        public void Properties()
        {
            Student2 stud = new Student2("Vijay Gawade", 23, "Pune");

            stud.Age  = 24;
            stud.Name = "Vijay R. Gawade";
            stud.Name = "";

            Console.WriteLine("Student Info:");
            Console.WriteLine("Name: " + stud.Name);
            Console.WriteLine("Age: " + stud.Age);
            Console.WriteLine("Address: " + stud.Address);
        }
コード例 #3
0
 void IncrementStudentAge(Student2 student, int age = 1)
 {
     student.Age += age;
 }