.net中的泛型
来源:互联网 发布:淘宝试用协议未同意 编辑:程序博客网 时间:2024/04/28 12:09
泛型把类或方法的类型的确定推迟到实例化该类或方法的时候 ,也就是说刚开始声明是不指定类型,等到要使用(实例化)时再指定类型
泛型可以用于 类、方法、委托、事件等
下面先写一个简单的泛型
public class GenericClass<T>
{
void SomeMethod( T t )
{
//do something
}
}
其使用方法如下:
实例化一个类
GenericClass<int> gci=new GenericClass<int>();方法SomeMethod就具有整数类型的参数了
下面写一个例子
using System;
using System.Collections.Generic;
using System.Text;
namespace example
{
class GenericClass<T>
{
public void PrintType(T t)
{
Console.WriteLine("Value:{0} Type:{1}",t,t.GetType());
}
}
class Program
{
static void Main(string[] args)
{
int i = 0;
GenericClass<int> gci = new GenericClass<int>();
gci.PrintType(i);
string s = "hello";
GenericClass<string> gcs = new GenericClass<string>();
gcs.PrintType(s);
Console.ReadLine();
}
}
}
- .net中的泛型
- .Net中的泛型
- .net中的泛型
- .net中的泛型
- .NET中的泛型
- .net中的泛型
- .net中的泛型
- .net中的泛型排序
- NET 中的泛型简介
- asp.net中的泛型
- .NET Framework 中的泛型概述
- 泛型在.NET中的应用
- .NET中的范型
- 简单分析.net泛型中的类型参数
- 简单分析.net泛型中的类型参数
- .NET中的泛型、接口、基类、继承混合使用
- .net泛型在构建JSON数据中的应用
- [C#基础知识]之 .net中的泛型全面解析
- uml建模工具介绍
- The method to fix "Please specify the assembly explicitly in the type name."
- VB中的dbGrid不能用,是怎么回事?在VB中运行后可以直接修改的控件是什么?
- 折腾吧
- Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
- .net中的泛型
- 论工作流——没有权限的概念
- WebApplication和WebSite对比
- 引导装载程序U-Boot的移植与应用
- 分享C#源代码,自动排课系统 V1.1(源码), 新闻自动采集系统(源码)
- 如何用好FIREFOX的XYZProxy
- 企业信息化的“四海归一”
- .net中的迭代器
- RDO和VB数据库编程