Type conversion, as well as the type of use is safe and as of

class Program 
    { 
        static  void the Main ( String [] args) 
        { 
            // . 1, type conversion 
            {
                 // implicit conversions: no transition, returns as a new Employee object, the Object is the base type Employee 
                Object O = new Employee ( ); 

                // display conversion: need to transform, as derived from Employee Object 
                Employee Employee = (Employee) O; 
            } 

            // 2, the type of security 
            {
                 // since Manager is derived from type Employee, normal operation 
                Manager m = new new Manager () ; 
                PromoteEmployee (m); 

                //Since DateTime not derived from type Employee, runtime exception is thrown
                 // DateTime = newYears new new DateTime (2019,. 8, 25);
                 // PromoteEmployee (newYears); 
            } 

            // . 3, is the type of inspection, is determined by the type of phase Bibi lower 
            / * 
             * this is due first of all to verify whether the operator is compatible with the Employee type o, o verify whether an Employee reference again 
             * 
             * is the type of inspection, never throw an exception, the result will only return true or false 
             * 
             * * * / 
            { 
                Object O = new new  Object ();
                 IF ((O IS  Object )) 
                { 

                } 
                IF ((OIS the Employee)) 
                { 

                } 
            } 

            // . 4, as the type of conversion, as determined by the type of performance can be improved 
            / * 
             * as the type of conversion, if the type of conversion is successful, the object is returned, otherwise null, this conversion mode will never thrown 
             * 
             * * * / 
            { 
                Object O = new new  Object (); 
                the Employee E = O AS the Employee;
                 IF (E =! null ) 
                { 

                } 
            } 

            // . 5, type switch as, a test 
            {
                 Object O =new new  Object (); 
                the Employee E = O AS the Employee; 
            } 

            // . 6, the type of conversion quizzes 
            {
                 // compilation error, since the converted display is not necessarily successful
                 // B = B1 new new Object ();
                 // D = D1 Object new new (); 

                // run error, since the converted display is not necessarily successful 
                B = B1 new new B (); 
                D D1 = (D) B1; 

                // run-time error, because the conversion is a necessarily succeed 
                Object O = new new  Object (); 
                B B2 = (B) O; 
            }
            The Console.ReadKey (); 
        } 
        // should be changed parameter type Object of type Employee, can be given at compile time so that 
        static  void PromoteEmployee ( Object O) 
        { 
            Employee E = (Employee) O; 
        } 
    } 
    class D: B 
    { 

    } 
    class B 
    { 

    } 
    public  class Manager: the Employee 
    { 
    } 
    public  class the Employee 
    { 
    }

 

Guess you like

Origin www.cnblogs.com/lishuyi/p/11408847.html