| Aspect |
C# Generics |
C++ Templates |
| Compilation |
Compiled once to IL; JIT specializes for value types |
Each instantiation compiled separately (code bloat possible) |
| Constraints |
Explicit where clauses; checked at compile time |
Duck typing; errors may be cryptic; concepts (C++20) improve this |
| Specialization |
Not directly supported; achieved via method overloads or interfaces |
Full / partial specialization supported |
| Reflection |
Generic type information available at runtime |
No runtime type info for templates |
| Value types |
Specialized native code per value type; no boxing |
Inlined at each instantiation; very efficient |