O'Reilly logo

Learning Object-Oriented Programming by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with generics in C#

We will create an IAnimal interface to specify the requirements that a type must meet in order to be considered an animal. We will create the Animal abstract base class that implements this interface. Then, we will specialize this class in two subclasses: Dog and Frog. Later, we will create the Party class that will be able to work with instances of any class that implements the IAnimal interface through generics. We will work with the party of dogs and frogs.

Now, we will create an IDeeJay interface and implement it in a HorseDeeJay class. We will also create a subclass of the Party class named PartyWithDeeJay that will use generics to work with instances of any type that implement the IAnimal interface and instances ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required