Ejemplo n.º 1
0
        public void TestReferenceTypes()
        {
            const int testSubject = 19;

            TestClass testClass; // 'testClass' reference is being stored in the stack

            testClass = new TestClass(10);

            Console.WriteLine("Before : " + testSubject + " ->" + testClass.AddToParameter(testSubject));
            ReferenceTypeManipulator(testClass);
            Console.WriteLine("After : " + testSubject + " ->" + testClass.AddToParameter(testSubject));

            //Send field as reference
            Console.WriteLine("Before : " + testClass.PublicField);
            FieldManipulatorRef(ref testClass.PublicField);
            Console.WriteLine("After : " + testClass.PublicField);

            //Send field as reference
            int notInitializedYet;

            Console.WriteLine("Before : " + testClass.PublicField);
            FieldManipulatorOut(out notInitializedYet);
            Console.WriteLine("After : " + testClass.PublicField);

            ////Can't send property as reference
            //Console.WriteLine("Before : " + testClass.PublicProperty);
            //FieldManipulator(ref testClass.PublicProperty);
            //Console.WriteLine("After : " + testClass.PublicProperty);
        }