[导入]Are Generics in .NET like Templates in C++?

本文探讨了CLR(公共语言运行时)中C#、Managed C++和VB.NET的泛型与C++模板之间的主要区别。重点在于泛型在运行时实例化而非编译时,并可通过元数据进行反射。此外,还介绍了类型参数访问约束验证机制的不同。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


No.

While Generic types do have a similar syntax to C++ templates, they are instantiated at runtime as opposed to compile time, and they can be reflected on via meta-data.  Also, in Generics, member access on the type paramater is verified based on the constraints placed on the type parameter; whereas, in templates, member access is verified on the type argument after instantiation.

Brandon Bray (Program Manager for the Visual C++ Compiler front-end at Microsoft) has a blog entry where he draws out the distinctions between Generics and Template.

Starting with VS 2005, C#, Managed C++, and VB will have CLR support for generics.  Read these two MSDN Magazine articles for more details. Introducing Generics in the CLR & More on Generics in the CLR

[Author: SantoshZ]

199940.aspx




本文转自斯克迪亚博客园博客,原文链接:http://www.cnblogs.com/sgsoft/archive/2004/09/22/45403.html,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值