Using Generics in C#
page 3 of 7
by Joydip Kanjilal
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 37637/ 73

How does C# Generics and C++ Templates compare?

According to MSDN, "Generics and templates are both language features that provide support for parameterized types. However, they are different and have different uses." C# generics and templates in C++ are more or less similar syntactically. However, there are some notable differences between them. C# Generic types are strong typed and they are instantiated at the runtime whereas C++ Templates are loosely typed and they are instantiated at the compile time only. Further, unlike C++ templates, Generics do not permit the type parameters to have default values.

MSDN states, "C++ templates use a compile-time model. When a template is used in a C++ program, the effect is as if a sophisticated macro processor had been used. C# generics are not just a feature of the compiler, but also a feature of the runtime. A generic type such as List<T> maintains its generic-ness (genericity) after it has been compiled. Or, to look at it another way, the substitution that the C++ compiler does at compile time is done at JIT time in the C# generic world."

View Entire Article

User Comments

No comments posted yet.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-20 9:07:00 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search