NetBlog主题

关于C# as类型转换
C#基础

关于C# as类型转换

3639

using System;namespace 类型转换 {class Program{static void Main(string[] args){try{Student s1 = new Student();Person p = new Person();//Student s2 = (Student)p;//这样父类转子类,虽然不报错,但运行时会出错Student s = p as Student;//这样转,如果成功则有返回值…