国产探花免费观看_亚洲丰满少妇自慰呻吟_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#排序比較

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 工布江达县| 东平县| 宁明县| 九寨沟县| 北票市| 巩留县| 武清区| 喀喇沁旗| 徐水县| 桐柏县| 隆子县| 翼城县| 定远县| 炉霍县| 海宁市| 衡东县| 龙州县| 盱眙县| 温州市| 嘉荫县| 兴文县| 金山区| 礼泉县| 芦山县| 崇义县| 宁陕县| 辽宁省| 平凉市| 望江县| 濮阳县| 洪江市| 吴堡县| 丰都县| 马龙县| 定南县| 昌宁县| 泾阳县| 墨竹工卡县| 太仆寺旗| 松潘县| 农安县|