Generics are a powerful feature of the C# language.This course will look at the built-in generic collections of the .NET framework, and use generic classes, interfaces, and delegates in building custom collections, and custom APIs for a repository and inversion of control container.
Generics are a powerful feature of the C# language that allow you to create type-safe data structures and APIs. This course will examine generics from every angle. We'll look at the built-in generic collections of the .NET framework, and use generic classes, interfaces, and delegates in building custom collections. There are tips for cleaning up and hiding generic noise from business logic, as well as a thorough demonstration of constraints, covariance, and contravariance in building APIs for a custom repository and inversion of control container.
Scott has over 15 years of experience in commercial software
development and is a frequent speaker at national conferences,
and local user groups. Scott is a Microsoft MVP and has authored
books on several Microsoft technologies, including ASP.NET, C#,
and Windows Workflow.
C# Generics - Why Generics? Hi, this is Scott Allen and this course will give you everything that you should ever know about Generics with C# and the CLR, perhaps even a bit more. In this first module, I want to show you some of the fundamentals that you should know about Generics, talk about why they exist, and the types of problems that they solve. But before we get into Generics, let me show you some code where I've been having a bit of a problem.
Working with Generic Collections Hi. This is Scott Allen, and in this module we will look at generic collections. Generics and collections work well together because collections are all about managing and organizing data. And quite often you want to organize a specific type of data like keep a list of employee objects around, and the list represents a department, a department of employees. Different collections have different strengths and weaknesses and capabilities, so it's good to know about all the options. Picking the wrong collection for a job can make life difficult, so let's look at the generic collections of. NET.
Generic Classes and Interfaces Hi. This is Scott Allen, and in this module we're going to return to the CircularBuffer we were looking at in the first module and dive into generics from the perspective of someone who has to write generic types. In the last module, we were a consumer of generics. We used various generic collections. But in this one, we're going to return to writing our own collection. We'll spend most of our time look at making some improvements to the CircularBuffer generic class, and we'll start using and writing some generic interfaces.
Generic Methods and Delegates Hi. This is Scott Allen, and in this module we'll be looking at using generic type parameters to genericize individual blocks of code. That means we'll be looking at generic methods, generic delegates, as well as taking a look at lambda expressions, extension methods, events, and event handlers, all of which can use generic type parameters so you can write more reusable blocks of code. Let's get started by looking at a generic method.
Constraints, Covariance, and Contravariance Hi. This is Scott Allen, and this module on C# Generics is going to look at strategies you can use to add constraints to your generic type parameters. Constraints will force the generic type arguments that come into a generic type to implement certain features. We'll also look at covariance and contravariance and see how these fancy-sounding terms can add some flexibility to your programs.
Generics and Reflection Hi. This is Scott Allen, and in this module we're going to create some interesting code with generics. I want to show you how to use generics when writing code that uses reflection, and then closely related, I thought it would be fun and educational to build an end version of control container. If you don't know about IoC containers or dependency injection, check out the Design Patterns library. But the container we will build will need generic type parameters, willneed to do some reflection, will need to build a fluent API that is easy to use and remember, and you'll see how to do all this and more in this module themed around reflection and generics.
Generic Odds & Ends Hi. This is Scott Allen, and this module is an assortment of odds and ends for generics, topics that didn't fit well into the rest of the story line, but I feel you should know about. We've already seen some tips and tricks in this course like how to work with unbound generics and refactor a covariant interface out of an invariant interface, but now we'll look at some of the things you cannot do with generics and some subtleties to be aware of.