Esempio n. 1
0
        public static void TestCaseRef()
        {
            Testref a = new Testref {
                Value = 10
            };

            Console.WriteLine("Before TestRef, a.Value:{0}", a.Value);

            TestRef(a);
            System.Diagnostics.Debug.Assert(a != null);

            Console.WriteLine("After TestRef, a.Value:{0}", a.Value);

            Console.WriteLine("Before TestRefEx, a.Value:{0}", a.Value);
            TestRefEx(ref a);
            System.Diagnostics.Debug.Assert(a != null);
            Console.WriteLine("After TestRefEx, a.Value:{0}", a.Value);

            string str_a = "IIIIIIIIIIIII";

            Console.WriteLine(str_a);

            string str_b = str_a;

            //str_b[0] = 'H';  //error, string is const

            Console.WriteLine("Before b=a, a.Value:{0}", a.Value);
            Testref b = a;

            b.Value = 120;
            Console.WriteLine("After b=120, a.Value:{0}", a.Value);
            b = null;
            Console.WriteLine("After b=null, a.Value:{0}", a.Value);
        }
Esempio n. 2
0
        public static void TestRefEx(ref Testref a)
        {
            a.Value = 30;

            //a = null; will trigger assert

            Testref b = new Testref {
                Value = 100
            };

            a = b;
        }
Esempio n. 3
0
 public static void TestRef(Testref a)
 {
     a.Value = 20;
     a       = null; // will not trigger assert
 }