Generics
noun
say it: “juh-NAIR-iks” /dʒəˈnɛrɪks/
Writing a class or method once with a type placeholder, like T, so it works safely with any type.
What is Generics in C#?
Generics — Type parameters that let classes and methods work safely with different types.
class ListReader
{
T First<T>(List<T> items)
{
return items[0];
}
}
In a sentence
- “Thanks to generics, List<Book> holds only books, and the compiler checks it.”
Level: Freelancer · More C# terms at this level
Updated