using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericClass
{
public abstract class BaseClass//普通基類
{
protected int name;//定義字段
public virtual int Name//定義屬性
{
set { name = value; }
get { return name; }
}
public BaseClass(int index)//構造函數
{
name = index;
}
public abstract void method(int t);//定義方法
}
public class GenericClass : BaseClass
{
protected new T name;//new 隐藏基類字段
public new T Name
{
get { return name; }//隻讀屬性
}
public GenericClass(int index): base(index)
{ }
public GenericClass(T t)
: base(1000)
{
name = t;
}
public override void method(int t)
{
Console.WriteLine("調用方法成功");
}
public void method(T t)
{ }
}
class Program
{
static void Main(string[] args)
{
int val = 1000;
GenericClass<</span>int> g = new GenericClass<</span>int>(val);
g.method(g.Name);
Console.WriteLine("泛型繼承示範成功,泛型類繼承普通類");
Console.ReadKey();
}
}
}