- 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 g = new GenericClass(val);
- g.method(g.Name);
- Console.WriteLine("泛型继承演示成功,泛型类继承普通类");
- Console.ReadKey();
- }
- }
- }
C#编程-105:泛型继承之泛型类继承普通类
关注
打赏