Beispiel #1
0
 static void Main(string[] args)
 {
     Console.WriteLine("Test passing class (reference type) by reference:");
     var s = new Student("Telerik Academy");
     Console.WriteLine(s.name);
     Student.IncorrectModifyStudent(s);
     Console.WriteLine(s.name);
     Student.ModifyStudent(ref s);
     Console.WriteLine(s.name);
     Console.WriteLine();
     Console.WriteLine("Test passing struct (value type) by reference:");
     Point p = new Point() { x = 5, y = -8 };
     Console.WriteLine(p.x + " " + p.y);
     MultiplyPoint.IncorectMultiply(p);
     Console.WriteLine(p.x + " " + p.y);
     MultiplyPoint.MultiplyBy2(ref p);
     Console.WriteLine(p.x + " " + p.y);
 }
Beispiel #2
0
 public static void ModifyStudent(ref Student student)
 {
     student = new Student("Changed: " + student.name);
 }
Beispiel #3
0
 public static void IncorrectModifyStudent(Student student)
 {
     student = new Student("Changed: " + student.name);
 }