Creating a generics interface class
Next, go to Solution Explorer
. Right-click on the name of the website, select Add
, and then click on Class
. Name the class GenInterface
and then click on OK
. When the Visual Studio message comes up, click on Yes
. Remember, this is just an example.
The code for the GenInterface
class is really complex. I'll create it now line-by-line, explaining what I'm doing and why I'm doing it.
First, delete everything except using System;
at the very top. Next, you'll make the class called Quad
for a four-sided shape of some kind. Enter the following after using System
:
public class Quad : IComparable<Quad>
This needs System
so that we can use IComparable
. If you right-click on it and select Go To Definition
in the drop-down menu (F12), you can see the definition of this thing. You will see namespace System
near the top, and the public intCompareTo (T other);
function after the Returns
definition, as shown in Figure 3.3.2:
Figure 3.3.2: The definition of IComparable...