里氏转换
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 里氏转换
{
class Program
{
static void Main(string[] args)
{
//字符转拼接
string a = string.Join("*",new int[]{1,2,3,4});
Console.Write(a);
Console.ReadLine();
string s = string.Join("+",1,false,'a',"张三");
Console.Write(s);
Console.ReadLine();
//里氏转换(强转的时候记得用as(返回对象) 或者 is(返回bool) )
Person a1 = new Student();
Teacher c1 = a1 as Teacher;
Student d1 = a1 as Student;
if (a1 is Student)
{
Student b1 = (Student)a1;
Console.Write("成功");
}
else
{
Console.Write("失败");
}
Console.ReadLine();
}
}
public class Person
{
}
public class Student:Person
{
}
public class Teacher:Person
{
}
}
浙公网安备 33010602011771号