国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【轉載】#438

2019-11-17 03:18:13
字體:
來源:轉載
供稿:網友

【轉載】#438 - Benefits of Using Interfaces

You might wonder why you'd define an interface, have a class implement that interface and then access the class through the interface instead of just using the class directly.

One benefit of interface is that it allows you to treat different types of objects in the same way, PRovided that they implement a common interface.

For example, assume that we have Dog, Seal and DrillSergeant classes, all of which implement the IBark interface (which contains a Bark method). We can now store a collection of instances of these classes and ask all objects in our collection to Bark by using the IBark interface.

 1 Dog kirby = new Dog("Kirby", 12); 2 Seal sparky = new Seal("Sparky"); 3 DrillSergeant sarge = new DrillSergeant("Sgt. Hartman", "Tough as nails"); 4  5 List<IBark> critters = new List<IBark>(){kirby, sparky, sarge}; 6  7 // Tell everyone to bark 8 foreach (IBark barkingCritter in critters) 9 {10     barkingCritter.Bark();11 }

原文地址:#438 - Benefits of Using Interfaces


上一篇:【轉載】#443

下一篇:C#排序比較

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰来县| 乌审旗| 宁陕县| 夏邑县| 潍坊市| 永济市| 宝山区| 丽水市| 南靖县| 平遥县| 泊头市| 大理市| 久治县| 阿瓦提县| 乃东县| 称多县| 连州市| 凉山| 南宫市| 墨脱县| 和龙市| 旌德县| 上思县| 通州区| 尚志市| 抚州市| 洛南县| 栾城县| 河南省| 潮州市| 寻乌县| 吉安市| 长子县| 噶尔县| 乌鲁木齐县| 安国市| 嘉荫县| 济宁市| 灌阳县| 丰台区| 额尔古纳市|