Esempio n. 1
0
        public static void MainST5()
        {
            Console.Write("\n\nWhen a struct and a class instance is passed to a method :\n");
            Console.Write("--------------------------------------------------------------\n");
            newStruct ns = new newStruct();
            newClass  nc = new newClass();

            ns.n = 5;
            nc.n = 5;
            //value of the struct field did not changed by passing its instance
            //because a copy of the struct was passed to the trackStruct method
            trackStruct(ns);
            //value of the class field changed by passing its instance
            //because a reference to the class was passed to the tracClass method
            tracClass(nc);
            Console.WriteLine("\nns.n = {0}", ns.n);
            Console.WriteLine("nc.n = {0}\n", nc.n);
        }
Esempio n. 2
0
 public static void tracClass(newClass cl)
 {
     cl.n = 8;
 }