This course introduces you to Generics in Visual Basic.NET. It starts with a discussion of what Generics are and why they were added to VB.NET and the .NET Framework. We then move to a demo heavy part of the course, looking at how to consume the Generic types included in .NET and how to create your own custom Generic classes and interfaces. The demos start out as simple and gradually get more complex as we get farther into the course. We finish with a discussion of Generic Covariance and Contravariance, names that make the topics seem much more complex than they really are.
Rob Windsor is a Senior Consultant and Trainer. He has almost twenty five
years' experience developing all types of applications and is currently
spending a majority of his time working with Office 365 and SharePoint.
Defining Generic Types Hi everybody. This is Rob Windsor, and in this module, which is part of our Generics and VB. NET course, we'll take a look at building custom generic types. This diagram shows what we ultimately want to build. The focus will be on the generic class XmlRepository. This class has collection-like functionality, but it will also allow us to persist objects in the application to disk as XML and then later on load that XML and rebuild those objects into memory. We'll be tackling the task of building this XmlRepository, as well as adding or updating other code within our application in four steps. In the first step, we'll be creating the IEntity and IRepository(Of T) interfaces. We'll also be implementing IEntity on the Shape and Employee classes. In the second step, we'll create the XmlRepository class and implement the collection functionality. In the third step, we'll be implementing the Commit method on the XmlRepository class to persist our data to disk as XML. And in the fourth step, we'll be adding the IXmlImport interface, implementing that interface on shape, circle, square, and employee, and then implementing the LoadXml method in the XmlRepository class. At the end of each step at the first, we'll be writing code in Module1 to check to see if our changes and additions are working as expected. (Waiting)
Generic Type Conversions Hi everybody. This is Rob Windsor, and this module, which is part of our Generics and VB. NET course, examines how type conversions or type casting works and sometimes doesn't work when you're programming with Generics. When you're looking at documentation on this subject, you'll see terms like variance, which is a general term to describe the phenomenon we're about to see, and covariance and contravariance, which are specific kinds of variances. I'm going to use these terms very infrequently because I think they just confuse the issue and make something that is actually quite simple seem quite complex.