顯式實現是什麼?C# 中何時在介面中使用它?
如果一個類實現了兩個包含相同簽名的成員的介面,那麼在類中實現該成員將導致兩個介面都將該成員用作它們的實現。
有可能顯式地實現一個介面成員——建立一個僅透過介面呼叫的類成員,並且特定於該介面
示例
interface ICar{ void display(); } interface IBike{ void display(); } class ShowRoom : ICar, IBike{ void ICar.display(){ throw new NotImplementedException(); } void IBike.display(){ throw new NotImplementedException(); } } class Program{ static void Main(){ Console.ReadKey(); } }
廣告