C#泛型比较大小
2024-09-12 14:02:16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 泛型比较大小
{
class Program
{
//Compare<T>是泛型类,T为类型参数
public class Compare<T> where T : IComparable
{
//使用泛型实现的比较方法
public static T compareGeneric(T t1, T t2)
{
if (t1.CompareTo(t2) > )
{
return t1;
}
else
{
return t2;
}
}
}
static void Main(string[] args)
{
//调用泛型方法
Console.WriteLine(Compare<int>.compareGeneric(, ));
Console.WriteLine(Compare<string>.compareGeneric("aa", "a"));
Console.ReadKey();
}
}
}
最新文章
- C# 对多个文件进行zip压缩
- 用Java实现网络爬虫
- Clr静态数据Table-Valued函数
- Shell 语法 if 、 case 、for 、 while、 until 、select 、repeat、子函数
- 使用VS把ASP.NET 5的应用发布到Linux的Docker上
- extjs ajax请求与struts2进行交互
- C# WinForm获取当前路径汇总
- class dict
- MAC OS JAVA环境变量配置
- js中动态载入css js样式
- eclipse创建项目时出现appcompat_v7包及解决办法
- Python的模块,模块的使用、安装,别名,作用域等概念
- INKDIE
- 【好程序员笔记分享】——UIView与CALayer详解
- RadioButton 和 RadioButtonList 比较
- PHP获得文件创建、修改、访问时间 filectime() filemtime() fileatime()
- Linux中MySQL5.6编译安装与MySQL5.7二进制安装步骤
- NOIP2017划水记
- NodeJS定时任务
- Mahout系列之----kmeans 聚类