using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 基类___派生类__向下转换
{
class Program
{
static void Main(string[] args)
{
B b = new B();
A a = b; //向下类型的转换
B b1 = a as B; // a返回 new B() 或者 null
b1.wordB();
/* if (a is B)
{
B b1 = (B)a;
b1.wordB();
}*/
}
}
class A
{
public void wordA()
{ Console.WriteLine("A"); }
public virtual void word()
{ Console.WriteLine("A1"); }
}
class B:A
{
public void wordB()
{ Console.WriteLine("B"); }
public override void word()
{ Console.WriteLine("B1"); }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 基类___派生类__向下转换
{
class Program
{
static void Main(string[] args)
{
B b = new B();
A a = b; //向下类型的转换
B b1 = a as B; // a返回 new B() 或者 null
b1.wordB();
/* if (a is B)
{
B b1 = (B)a;
b1.wordB();
}*/
}
}
class A
{
public void wordA()
{ Console.WriteLine("A"); }
public virtual void word()
{ Console.WriteLine("A1"); }
}
class B:A
{
public void wordB()
{ Console.WriteLine("B"); }
public override void word()
{ Console.WriteLine("B1"); }
}
}