Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

What’s a Generic?

A generic, also called a parameterized type in the Unified Modeling Language (UML) or template in C++, is the abstraction of the data type from algorithm or class. For example, a sort is a sort. If you uncouple the data type from the sort algorithm, you get the same basic behavior.

Generics are an evolution of C-style macros. In the C programming language, a macro was code that was plugged in where a placeholder was used by the pre-compiler. The problem with macros was that they weren’t type-checked, so templates were added as a full-fledged language feature for C++ and ultimately found its way into C# (and Visual Basic) .NET.

Generics use a notation like Func<T>, where T is the parameter type to be defined. For example, Func<int> means that everywhere the parameter T is used as a placeholder for a data type, the actual type used at the point of declarations is used instead.

  • + Share This
  • 🔖 Save To Your Account