From the course: C#: Interfaces and Generics

Unlock this course with a free trial

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

What are generics?

What are generics?

- Now let's take a quick look at generics. Again, we'll get into more detail on this later in the course, but for the moment, I just want to explain a little bit about what generics are. Generics were introduced way back in C# 2.0, and they brought with them the ability to combine type safety, reusability, and efficiency, to certain kinds of C# operations. They are usually used when working with collections of data. Now that's not the only way that generics can be used in C#, but it's the most common way. And it's what we're going to focus on here in this course, generics, give your code away to tell the C# compiler, what kind of data type you intend to use with a given class, without that class having to know about that data type in advance. So perhaps an example will explain things a little bit better. So let's imagine that you have an array of data and you know in advance that you only ever want this array to contain integers, no strings, no custom objects, just plain integers…

Contents