C#编程-105:泛型继承之泛型类继承普通类_彭世瑜_新浪博客
发布日期:2021-07-01 06:18:31
浏览次数:2
分类:技术文章
本文共 883 字,大约阅读时间需要 2 分钟。
- 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();
- }
- }
- }
转载地址:https://pengshiyu.blog.csdn.net/article/details/109661848 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年05月07日 10时46分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
[12] JMeter-结果分析之图形图表
2019-05-01
使用aspose.words 18.6实现pdf文档转换
2019-05-01
Java数组详解
2019-05-01
vs中动态DLL与静态LIB工程中加入版本信息的方法
2019-05-01
大数据分析技术与应用一站式学习(值得收藏)_v20200418
2019-05-01
自定义Starter
2019-05-01
分布式事务原理探究(一)
2019-05-01
映 射 ALT 键
2019-05-01
vim使用快捷键F4生成文件头注释、F5生成main函数模板、F6生成.h文件框架模板
2019-05-01
OV5620的视频驱动
2019-05-01
C++中两个类交叉定义或递归定义的解决办法
2019-05-01
记一次Hive 行转列 引起的GC overhead limit exceeded
2019-05-01
OpenGL ES八 - 交叉存取顶点数据
2019-05-01
crontab定时任务写法
2019-05-01
nginx: [emerg] unknown directive "if($remote_addr" in /usr/local/tools/nginx/conf/nginx.conf:57
2019-05-01
module pip has no attribute main问题解决
2019-05-01
LeetCode 134.Gas Station (加油站)
2019-05-01
Python之命名元组 (namedtuple)
2019-05-01
使用libpcap过滤arp
2019-05-01