Exemple #1
0
        static void DoWithSomeType(object obj)
        {
            //SecondType secondType = (SecondType)obj;
            SecondType secondType = obj as SecondType;

            if (secondType != null)
            {
                // do someting
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            FirstType firstType = new FirstType()
            {
                Name = "First Type"
            };
            SecondType secondType = (SecondType)firstType;         //转型成功

            //secondType = firstType as SecondType;     //编译期转型失败,编译不通过

            Console.Read();
        }