A little while ago, a friend of mine on Facebook asked me to explain to him what generics in .NET were. As I thought this might interest more than one friend, which it did, I decided to put it in a "note" on Facebook. That was before I started this blog, so now I decided to post it here, hopefully so that more people would find it useful.
Generics in the .NET
Framework is a programming technique that allows you to create a
"generic" (meaning that it's not tied to a specific type) class,
structure or method. The type, which is in this case "an argument", is specified when that element is used. What's interesting,
and this is another advantage of Generics in .NET, is that you can restrict that type
by specifying, for example, that it has to implement a certain interface or have a parameterless constructor.
This concept allows
for more type safety (the type is known when the generic element is being used), while
promoting reuse (you create an element that's not tied to a specific type).