If one passes an object to a method using the \'Ref\' keyword then what is the difference with passing it without the ref keyword?
Because both yield the same result, th
Try reassigning the student object rather than setting properties of it.
public static void SetStudent( ref Student student )
{
student = new Student();
student.Age = 16;
student.Name = "StudentY";
}
public static void AnotherStudent( Student studenta )
{
studenta = new Student();
studenta.Age = 12;
studenta.Name = "StudentX";
}
Don't think of ref
as "passing by reference" because all reference types are passed by reference. Think of it as "reference to this object can be reassigned"