O'Reilly logo

C# 7 and .NET Core Cookbook by Dirk Strauss

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

How to do it...

Let's take a look at the following implementation of the generic interface as follows:

  1. Go ahead and create a generic interface called IListClassProperties<T>. The interface will define a method that needs to be used called GetPropertyList() that simply uses a LINQ query to return a List<string> object:
        interface IListClassProperties<T>         {           List<string> GetPropertyList();         }
  1. Next, create a generic class called InspectClass<T>. Let the generic class implement the IListClassProperties<T> interface created in the previous step:
        public class InspectClass<T> : IListClassProperties<T>         {         }
  1. As usual, Visual Studio will highlight that the interface member GetPropertyList() has not been implemented in the InspectClass<T>

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