什么是C#泛型? [英] What are generics in C#?

查看:136
本文介绍了什么是C#泛型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是泛型在C#中,用一个简单的例子来说明?什么是这个主题的一些相关的文章或网站?

What are generics in C#, illustrated with a simple example? What are some related articles or websites for this topic?

推荐答案

泛型是指写code一类不指定数据类型(S),类作品上的技术。

Generics refers to the technique of writing the code for a class without specifying the data type(s) that the class works on.

在声明泛型类的实例时指定的数据类型。这允许专门的通用类的许多不同的数据类型,而仅具有编写一次类

You specify the data type when you declare an instance of a generic class. This allows a generic class to be specialized for many different data types while only having to write the class once.

一个很好的例子是在.NET中的许多集合类。每个集合类都有它自己的执行如何被创建的收集和管理。但他们使用仿制药,让自己的类来与任何类型的集合工作。

A great example are the many collection classes in .NET. Each collection class has it's own implementation of how the collection is created and managed. But they use generics to allow their class to work with collections of any type.

<一个href=\"http://msdn.microsoft.com/en-us/library/ms379564(VS.80).aspx\">http://msdn.microsoft.com/en-us/library/ms379564(VS.80).aspx

这篇关于什么是C#泛型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆