C#编程-106:泛型继承之普通类继承泛型类_彭世瑜_新浪博客
彭世瑜 发布时间:2017-08-08 23:01:38 ,浏览量:1
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- namespace GenericClassTwo
- {
- public abstract class GenericClass//泛型类
- {
- protected T field;
- public virtual T Property
- {
- get { return field; }
- }
- public GenericClass(int index) { }
- public GenericClass(T t)
- {
- field = t;
- }
- public abstract void method(T t);
- }
- class OrdinaryClass : GenericClass//普通类
- {
- public override int Property
- {
- get
- {
- return base.Property;
- }
- }
- public OrdinaryClass(int t) : base(t) { }
- public override void method(int t)
- {
- Console.WriteLine("property value ={0}",t);
- }
-
- }
- class Program
- {
- static void Main(string[] args)
- {
- int val = 1000;
- OrdinaryClass or = new OrdinaryClass(val);
- or.method(val);
- Console.WriteLine("普通类继承泛型类演示成功");
- Console.ReadKey();
- }
- }
- }
1665367115
查看更多评论