예제 #1
0
        static void Main(string[] args)
        {
            MyClass objectA = new MyClass();
            MyClass objectB = new MyClass();

            WriteLine($"objectA == objectB? {objectA == objectB}");
            MyClass objectC = objectB;

            WriteLine($"objectC == objectB? {objectC == objectB}");
            objectB = objectA;
            WriteLine($"objectA == objectB? {objectA == objectB}");
            WriteLine($"objectA == objectC? {objectA == objectC}");
            WriteLine(objectA);
            WriteLine(objectB);

            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"objectC.val = {objectC.val}");
            WriteLine();

            objectA.val = 10;
            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"objectC.val = {objectC.val}");
            WriteLine();

            objectB.val = 20;
            myStruct structA = new myStruct();
            myStruct structB = structA;

            WriteLine(structA);
            WriteLine(structB);

            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
            WriteLine();

            structA.val = 30;
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
            WriteLine();

            structB.val = 40;
            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"objectC.val = {objectC.val}");
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
            WriteLine();

            structB = structA;
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");

            ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: niuniuliu/CSharp
 static void Main(string[] args)
 {
    MyClass objectA = new MyClass();
    MyClass objectB = objectA;
    objectA.val = 10;
    objectB.val = 20;
    myStruct structA = new myStruct();
    myStruct structB = structA;
    structA.val = 30;
    structB.val = 40;
    Console.WriteLine("objectA.val = {0}", objectA.val);
    Console.WriteLine("objectB.val = {0}", objectB.val);
    Console.WriteLine("structA.val = {0}", structA.val);
    Console.WriteLine("structB.val = {0}", structB.val);
    Console.ReadKey();
 }
예제 #3
0
        static void Main(string[] args)
        {
            MyClass objectA = new MyClass();
            MyClass objectB = objectA;

            objectA.val = 10;
            objectB.val = 20;
            myStruct structA = new myStruct();
            myStruct structB = structA;

            structA.val = 30;
            structB.val = 40;
            Console.WriteLine("objectA.val = {0}", objectA.val);
            Console.WriteLine("objectB.val = {0}", objectB.val);
            Console.WriteLine("structA.val = {0}", structA.val);
            Console.WriteLine("structB.val = {0}", structB.val);
        }
예제 #4
0
        static void Main(string[] args)
        {
            MyClass objectA = new MyClass();
            MyClass objectB = objectA;

            objectA.val = 10;
            objectA.val = 20;
            myStruct structA = new myStruct();
            myStruct structB = structA;

            structA.val = 30;
            structB.val = 40;
            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
            ReadKey();
        }
예제 #5
0
        static void Main(string[] args)
        {
            MyClass objectA = new MyClass();
            // objectB == objectA
            // objectB refereerd naar zelfde plek als objectA
            MyClass objectB = objectA;

            objectA.val = 10;
            objectB.val = 20;

            myStruct structA = new myStruct();
            // structB = structA
            // structB krijgt de waarde van structA
            myStruct structB = structA;

            structA.val = 30;
            structB.val = 40;

            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
        }
예제 #6
0
        static void Main(string[] args)
        {
            // Classes are reference types, so copying a class object to a different
            // variable will copy a reference to the SAME OBJECT to the new variable.
            MyClass objectA = new MyClass();
            MyClass objectB = objectA;

            objectA.val = 10;
            objectB.val = 20;

            // Structures are value types, so copying a structure object to a different
            // variable will create a NEW COPY of the structure in the new variable.
            myStruct structA = new myStruct();
            myStruct structB = structA;

            structA.val = 30;
            structB.val = 40;

            WriteLine($"objectA.val = {objectA.val}");
            WriteLine($"objectB.val = {objectB.val}");
            WriteLine($"structA.val = {structA.val}");
            WriteLine($"structB.val = {structB.val}");
            ReadKey();
        }