为什么C#和VB有泛型?提供什么好处?泛型,FTW好处、有泛型、VB、泛型

2023-09-03 01:32:13 作者:情话烫舌.

从维基百科:

泛型编程是一种风格   计算机编程中,   算法都写在计   给被指定-存货的类型是   然后在需要的时候实例化   作为参数的特定类型   并率先通过阿达其中   出现在1983年。这种方法   允许编写常用功能或   仅不同的组类型   在其使用时,他们经营类型,   从而减少重复。

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983. This approach permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplication.

泛型提供了定义稍后指定类型的能力。你不必投项目类型使用它们,因为它们已经打出来。

Generics provide the ability to define types that are specified later. You don't have to cast items to a type to use them because they are already typed.

为什么C#和VB有泛型?提供什么好处?你觉得什么好处使用它们?

Why does C# and VB have Generics? What benefit do they provide? What benefits do you find using them?

还有什么其他语言也有仿制药?

What other languages also have generics?

推荐答案

C#和VB有仿制药采取底层CLR优势的泛型支持(或者是周围的其他方式?)。它们允许你写code INA静态类型语言,可以适用于不止一种类型,而无需使用重写$ C $下将其用于(运行时会为你做的),每种类型或以其他方式 System.Object的和铸造无处不在(如我们不得不做的ArrayList)。

C# and VB have generics to take advantage of generics support in the underlying CLR (or is the other way around?). They allow you to write code ina statically-typed language that can apply to more than one kind of type without rewriting the code for each type you use them for (the runtime will do that for you) or otherwise using System.Object and casting everywhere (like we had to do with ArrayList).

你阅读文章?

这些语言中也有泛型:

在C ++(通过的模板的) 艾达(通过的模板的) 在艾菲尔 D(通过的模板的) 哈斯克尔 的Java C++ (via templates) Ada (via templates) Eiffel D (via templates) Haskell Java
 
精彩推荐
图片推荐