admin管理员组文章数量:1636896
It's possible for a class to implement more than one interface.
For example, a Cow class might implement both the IMoo and the IMakeMilk interfaces. Multiple interfaces are listed after the class declaration, separated by commas.
1 public class Cow: IMoo, IMakeMilk 2 { 3 public void Moo() 4 { 5 // do mooing here 6 } 7 8 public double Milk() 9 { 10 // do milking here 11 } 12 }
You can now use an instance of the Cow class to access members of either interface.
1 Cow bossie = new Cow("Bossie", 12); 2 3 // Call both IMoo and IMakeMilk methods 4 bossie.Moo(); // IMoo.Moo 5 double numGallons = bossie.Milk(); // IMakeMilk.Milk
We can also set interface variables of either interface type to an instance of a Cow.
1 IMoo mooStuff = bossie; 2 IMakeMilk milkStuff = bossie; 3 4 mooStuff.Moo(); 5 numGallons = milkStuff.Milk();
原文地址:#440 - A Class Can Implement More than One Interface
转载于:https://wwwblogs/yuthreestone/p/3596643.html
版权声明:本文标题:【转载】#440 - A Class Can Implement More than One Interface 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729234972a1191886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论