From the course: C#: Applied Data Structures

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Generic vs. non-generic collections

Generic vs. non-generic collections

From the course: C#: Applied Data Structures

Generic vs. non-generic collections

- [Instructor] Let's examine the differences between the generic and non-generic collection classes a little more closely. The .NET framework supports both, generic and non-generic collection types. But for the most part, Microsoft recommends that you should use the generic versions in any new code that you write. Generic collections were introduced way back in .NET 2.0 and have several benefits associated with them that the non-generic versions don't have. If you're not familiar with generics, then I suggest you watch the C# Interfaces and Generics course to learn more about what they are and how they're used. The generic versions of the data structure classes provide type safety at compile time, which helps to reduce programming errors. This is because when you declare a generic data structure, you provide a type argument, which restricts that collection to containing only objects of that type. So for example, I can…

Contents