コード例 #1
0
        static void Main(string[] args)
        {
            //  Passing ref-types by value.
            Console.WriteLine("***** Passing Person object by value *****");
            Person fred = new Person("Fred", 12);
            Console.WriteLine("]nBefore by value call, Person is:");
            fred.Display();

            SendAPersonByValue(fred);
            Console.WriteLine("\nAfter by value call, Person is:");
            fred.Display();

            //  Passing ref-types by reference.
            Console.WriteLine("\n***** Passing Person object by reference *****");

            Person mel = new Person("Mel", 23);
            Console.WriteLine("Before by ref call, Person is:");
            mel.Display();

            SendAPersonByReference(ref mel);
            Console.WriteLine("After by ref call, Person is:");
            mel.Display();

            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: usedflax/flaxbox
        static void SendAPersonByValue(Person p)
        {
            // Change the age of "p"?
            p.personAge = 99;

            // Will the caller see this reassignment?
            p = new Person("Nikki", 99);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: usedflax/flaxbox
        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);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Passing a class by value");
            Person fred = new Person("Fred", 12);
            Console.WriteLine("Before pass by val: ");
            fred.Display();

            SendAClassByValue(fred);

            Console.WriteLine("After pass by val");
            fred.Display();

            SendAClassByReference(ref fred);
            Console.WriteLine("After pass by ref");
            fred.Display();

            Console.ReadLine();

            //Person p = new Person();
        }
コード例 #5
0
        static void SendAClassByReference(ref Person p)
        {
            p.personAge = 555;

            p = new Person("Nikki", 999);
        }
コード例 #6
0
        static void SendAClassByValue(Person p)
        {
            p.personAge = 99;

            p = new Person("Nikki", 99);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: lrymal/Self-Study-C-Sharp
 static void SendAPersonByValue(Person p) {
     //change the age of "p"? YUUUP
     p.personAge = 99;
     //will the caller see this reassignment?  NEWP
     p = new Person("Nikki", 99);
 }