private static void Main(string[] args) { Console.WriteLine("Assigning value types\n"); Point p1 = new Point(10, 10); Point p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); Console.WriteLine("Assigning reference types\n"); PointRef pr1 = new PointRef(10, 10); PointRef pr2 = pr1; pr1.Display(); pr2.Display(); pr1.X = 100; Console.WriteLine("\n=> Changed pr1.X\n"); pr1.Display(); pr2.Display(); Console.WriteLine(); ValueTypeContainingsRefType(); Console.ReadLine(); }
static void ReferenceTypesAssignment() { Console.WriteLine("assigning value types \n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("\n change p1.X\n"); p1.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { Console.WriteLine("Assigning Reference Types\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { Console.WriteLine("Assigning Reference Types"); PointRef p = new PointRef(50, 60); PointRef p2 = p; p.Display(); p2.Display(); p.x = 100; p.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { Console.WriteLine("=> ref type assignment"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("=> changed p1.X"); p1.Display(); p2.Display(); Console.WriteLine(); }
private static void ReferenceTypeAssignment() { PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; // Print both point refs. p1.Display(); p2.Display(); // Change p1.X and print again p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); Console.WriteLine(); }
static void AssignRefTypes() { Console.WriteLine("Assigning reference types \n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; // Print both point refs. p1.Display(); p2.Display(); // Change p1.X and print again. p1.X = 100; Console.WriteLine("\n => Changed p1.X \n"); p1.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { Console.WriteLine("Assigning reference type\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; // Print both point refs. p1.Display(); p2.Display(); // Change p1.X and print again. p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { WriteLine("Assigning reference types\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; // Print both point refs. p1.Display(); p2.Display(); // Change p1.X and print again. p1.X = 100; WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); WriteLine(); }
//Assigning to intrinsic value types results in //two independent variables on the stack. static void ValueTypeAssignment() { Console.WriteLine("Assinging value types\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; //Print both points. p1.Display(); p2.Display(); //Chage p1.X and print again. p2.X is changed to by reference p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); }
static void ReferenceTypeAssignment() { // equals to method ValueTypeAssignment except the use of PointRef class Console.WriteLine("Assigning reference types: \n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); //Изменить pl.X и снова вывести значения переменных.Значение р2.Х ИЗМЕНИЛОСЬ тк ссылочный тип. p1.X = 100; Console.WriteLine("\n=> Changed pl.X\n"); p1.Display(); p2.Display(); Console.WriteLine(); }
static void ReferenceTypeAssignment() { Console.WriteLine("Assigning reference types\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; // p2 now POINTS to the location in memory of p1 // Print both refs. p1.Display(); p2.Display(); // Change p1.y and print again p1.y = 99; Console.WriteLine("\n=> p1.y changed\n"); p1.Display(); p2.Display(); // In this case there are two references pointing to the same // object on the managed heap. }
static void ReferenceTypeAssignment() { Console.WriteLine("Assigning reference types\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("\n=> Changed p1.X\n"); p1.Display(); p2.Display(); }