C#编程-106:泛型继承之普通类继承泛型类_彭世瑜_新浪博客
发布日期:2021-07-01 06:18:30 浏览次数:2 分类:技术文章

本文共 766 字,大约阅读时间需要 2 分钟。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace GenericClassTwo
  7. {
  8.     public abstract class GenericClass//泛型类
  9.     {
  10.         protected T field;
  11.         public virtual T Property
  12.         {
  13.             get return field; }
  14.         }
  15.         public GenericClass(int index) { }
  16.         public GenericClass(T t)
  17.         {
  18.             field = t;
  19.         }
  20.         public abstract void method(T t);
  21.     }
  22.     class OrdinaryClass : GenericClass<</span>int>//普通类
  23.     {
  24.         public override int Property
  25.         {
  26.             get
  27.             {
  28.                return base.Property;
  29.             }
  30.         }
  31.         public OrdinaryClass(int t) : base(t) { }
  32.         public override void method(int t)
  33.         {
  34.             Console.WriteLine("property value ={0}",t);
  35.         }
  36.      
  37.     }
  38.     class Program
  39.     {
  40.         static void Main(string[] args)
  41.         {
  42.             int val = 1000;
  43.             OrdinaryClass or = new OrdinaryClass(val);
  44.             or.method(val);
  45.             Console.WriteLine("普通类继承泛型类演示成功");
  46.             Console.ReadKey();
  47.         }
  48.     }
  49. }

转载地址:https://pengshiyu.blog.csdn.net/article/details/109661847 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C#编程-105:泛型继承之泛型类继承普通类_彭世瑜_新浪博客
下一篇:C#编程-104:泛型的开放类型与封闭类型_彭世瑜_新浪博客

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月27日 16时12分03秒