c# - 为什么C#和VB有泛型?他们提供什么好处?泛型,FTW

标签 c# .net vb.net generics

来自 Wikipedia :

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.

泛型提供了定义稍后指定的类型的能力。您不必将项目转换为类型即可使用它们,因为它们已经被键入。

为什么C#和VB有泛型?他们提供什么好处?您发现使用它们有什么好处?

还有哪些其他语言也有泛型?

最佳答案

C# 和 VB 具有泛型以利用底层 CLR 中的泛型支持(或者相反?)。它们允许您使用静态类型语言编写代码,这种语言可以应用于多种类型,而无需为您使用它们的每种类型重写代码(运行时将为您完成)或以其他方式使用 System.Object 和到处转换(就像我们必须对 ArrayList 做的那样)。

你读过 article 了吗? ?

这些语言也有泛型:

  • C++(通过模板)
  • Ada(通过模板)
  • 埃菲尔铁塔
  • D(通过模板)
  • haskell
  • Java

关于c# - 为什么C#和VB有泛型?他们提供什么好处?泛型,FTW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/99686/

相关文章:

.net - 学习正则表达式模式的算法

c# - .NET Core 中当前位置的堆栈跟踪

c# - ILogger 的 CaSTLe Windsor Visual Studio 代码片段

c# - Response.Redirect 与查询字符串

java - 使用 java 通过 TransportWithMessageCredentials (UserName) 访问 WCF 服务

.net - 带有嵌套控件的设计模式

database - 简单的 VB 2010 应用程序不将数据保存到 Access 2007

C# 按钮仅在第二次单击时触发

c# - 如何禁用 WebBrowser 鼠标中键单击自动滚动?

vb.net - VB.Net 接口(interface)中的可选只读属性