111,097
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Animal
{
public void A() { Console.WriteLine("A"); }
}
class Dog : Animal
{
public new void A() { Console.WriteLine("D"); }
}
class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.A();
((Animal)dog).A();
}
}
}
[/quote]
向上转型:upcasting 所有面向对象语言的基础语法之一,忘了在哪本书上看的了using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Animal
{
public void A() { Console.WriteLine("A"); }
}
class Dog : Animal
{
public new void A() { Console.WriteLine("D"); }
}
class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.A();
((Animal)dog).A();
}
}
}