public CovaInArray()
 {
     //Implicit conversion of array of more derived to a less derived type.
     Mamals[] mArray = new Lion[3];
     mArray[0] = new Lion();
     Console.WriteLine(mArray[0].GetType());
     object[] o = new string[2];
     o[0] = "123";
     //Not type safe the statement below will throw an exception
     o[1] = 123;
 }
Esempio n. 2
0
        public void Sample()
        {
            //Boxing and Unboxing (Is/As/Cast)
            Lion   _lion = new Lion();
            Mamals _mamals1;
            Mamals _mamals2;

            //Use the is operator to verify the type before performing a cast.
            if (_lion is Mamals)
            {
                _mamals1 = (Mamals)_lion;
                Console.WriteLine(_mamals1.GetType());
            }

            _mamals2 = _lion as Mamals;
            if (_mamals2 != null)
            {
                Console.WriteLine(_mamals2.ToString());
            }
        }
 public void LionMove(Lion l)
 {
 }
 public Mamals Method1(Lion l)
 {
     return(new Mamals());
 }