C#泛型类创建与使用的方法
作者:cnc 时间:2023-02-28 21:26:36
本文实例为大家分享了C#泛型类创建与使用的具体代码,供大家参考,具体内容如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Test<string,int> t = new Test<string,int>("Age",16);
t.Run();
t.SetT1Value = "Height";
t.SetT2Value = 1000;
t.Run();
Console.ReadKey();
}
}
class Test<T1,T2>
{
private T1 _t1;
private T2 _t2;
public Test(T1 v1,T2 v2)
{
_t1 = v1;
_t2 = v2;
}
public T1 SetT1Value
{
set
{
_t1 = value;
}
}
public T2 SetT2Value
{
set
{
_t2 = value;
}
}
public void Run()
{
Console.WriteLine("The type of T1 is {0},the value is {1}",_t1.GetType().ToString(),_t1);
Console.WriteLine("The type of T2 is{0},the value is {1}", _t2.GetType().ToString(), _t2);
}
}
}
运行结果:
标签:C#,泛型类
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java操作redis设置第二天凌晨过期的解决方案
2022-11-15 11:40:10
C#获取上个月第一天和最后一天日期的方法
2023-02-22 07:33:44
深入解析Java的设计模式编程中建造者模式的运用
2022-08-10 23:31:22
![](https://img.aspxhome.com/file/2023/5/76315_0s.jpg)
详解Java中的final关键字
2023-02-20 17:29:50
ava实现一致性Hash算法
2022-09-18 00:44:33
![](https://img.aspxhome.com/file/2023/5/85825_0s.jpg)
Java性能优化技巧汇总
2023-01-05 16:26:31
spring security在分布式项目下的配置方法(案例详解)
2022-12-26 03:45:49
Spring Boot Logback配置日志过程解析
2022-12-09 18:08:06
Java中利用gson解析Json实例教程
2023-10-31 04:07:41
![](https://img.aspxhome.com/file/2023/1/70511_0s.png)
C# 调用API函数弹出映射网络驱动器对话框问题
2023-03-25 15:41:05
linux的shell命令检测某个java程序是否执行
2021-07-27 14:32:20
java 引用传递的三种类型小结
2023-09-03 03:59:47
![](https://img.aspxhome.com/file/2023/0/60560_0s.png)
C#自定义签名章实现方法
2022-08-02 05:22:37
用Flutter开发自定义Plugin的方法示例
2023-07-05 00:19:40
![](https://img.aspxhome.com/file/2023/3/99793_0s.png)
springboot项目快速搭建的方法步骤
2021-11-07 04:55:51
![](https://img.aspxhome.com/file/2023/4/73074_0s.png)
Java 中的HashMap详解和使用示例_动力节点Java学院整理
2022-06-10 18:08:51
![](https://img.aspxhome.com/file/2023/8/94338_0s.png)
SpringBoot基于Sentinel在服务上实现接口限流
2023-11-27 17:19:25
![](https://img.aspxhome.com/file/2023/4/59574_0s.jpg)
Commons beanutils组件简介
2023-11-28 07:13:27
Java基于链表实现栈的方法详解
2022-07-02 11:39:20
![](https://img.aspxhome.com/file/2023/5/66045_0s.png)
Java编程中使用XFire框架调用WebService程序接口
2023-11-06 20:16:33
![](https://img.aspxhome.com/file/2023/0/58990_0s.png)