- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 273字
- 2021-07-02 15:29:18
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:

Notice that it returns an integer. So, when we implement this interface, we have to keep that in mind. Now, close the definition window.
In our particular case, enter the following text below the open curly brace under the line beginning with public class Quad...:
private string name;
public Quad(string na)
Now, to set the value, enter the following between a set of curly braces beneath the preceding lines:
name = na;
After all, every quadrilateral shape, which is a square, rectangle, or rhombus, all have a name, don't they? So, it's a good idea to centralize the name feature in the Quad class.
- Backbone.js Blueprints
- Scala謎題
- Instant Nancy Web Development
- 軟件測(cè)試實(shí)用教程
- Swift 4 Protocol-Oriented Programming(Third Edition)
- MATLAB GUI純代碼編寫從入門到實(shí)戰(zhàn)
- 自學(xué)Python:編程基礎(chǔ)、科學(xué)計(jì)算及數(shù)據(jù)分析(第2版)
- 零基礎(chǔ)學(xué)C語(yǔ)言(升級(jí)版)
- AMP:Building Accelerated Mobile Pages
- Android Studio開(kāi)發(fā)實(shí)戰(zhàn):從零基礎(chǔ)到App上線 (移動(dòng)開(kāi)發(fā)叢書(shū))
- Google Adsense優(yōu)化實(shí)戰(zhàn)
- C# 10核心技術(shù)指南
- 開(kāi)源網(wǎng)絡(luò)地圖可視化:基于Leaflet的在線地圖開(kāi)發(fā)
- PHP從入門到精通(微視頻精編版)
- Java Web開(kāi)發(fā)任務(wù)教程