Ejemplo n.º 1
0
 static void SendAPersonByValue(Person p)
 {
     // Change the age of "p"?
     p.personAge = 99;
     
     // Will the caller see this reassignment?
     p = new Person("Nikki", 99);
 }
Ejemplo n.º 2
0
 static void SendAPersonByReference(ref Person p)
 {
     // Change some data of "p".
     p.personAge = 555;
     // "p" is now pointing to a new object on the heap!
     p = new Person("Nikki", 999);
 }
Ejemplo n.º 3
0
        //Structures are System.ValueType. Their behavier is like System.Int32 local vars. They are popped off the stack after their visibility block ends.
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            //valueTypeCopying();
            //refTypeCopying();
            //copyValueTypesContainingRefType();
            
            Person p = new Person("Ivan", 34);
            p.Display();
            SendAPersonByValue(p);
            p.Display();
            SendAPersonByReference(ref p);
            p.Display();

            Console.ReadLine();
        }