コード例 #1
0
        static void Main()
        {
            // create a myStruct object
            myStruct theStruct = new myStruct();

            theStruct.Status = -1; // initialize
            Console.WriteLine(
                "theStruct.Status: {0}", theStruct.Status);

            // Change the value
            theStruct.Status = 2;
            Console.WriteLine("Changed object.");
            Console.WriteLine(
                "theStruct.Status: {0}", theStruct.Status);

            // cast to an IStorable
            // implicit box to a reference type
            IStorable isTemp = ( IStorable )theStruct;

            // set the value through the interface reference
            isTemp.Status = 4;
            Console.WriteLine("Changed interface.");
            Console.WriteLine("theStruct.Status: {0}, isTemp: {1}",
                              theStruct.Status, isTemp.Status);

            // Change the value again
            theStruct.Status = 6;
            Console.WriteLine("Changed object.");
            Console.WriteLine("theStruct.Status: {0}, isTemp: {1}",
                              theStruct.Status, isTemp.Status);
        }
コード例 #2
0
        static void Main()
        {
            myStruct theStruce = new myStruct();

            theStruce.Status = -1;
            Console.WriteLine("theStruce.Status: {0}", theStruce.Status);

            theStruce.Status = 2;
            Console.WriteLine("Changed object.");
            Console.WriteLine("theStruct.Status: {0}", theStruce.Status);

            IStorable isTemp = (IStorable)theStruce;

            isTemp.Status = 4;
            Console.WriteLine("Changed interface.");
            Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruce.Status, isTemp.Status);

            theStruce.Status = 6;
            Console.WriteLine("Changed object.");
            Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruce.Status, isTemp.Status);
        }