| title | How to: Explicitly Implement Interface Members (C# Programming Guide) | |
|---|---|---|
| ms.date | 07/20/2015 | |
| ms.prod | .net | |
| ms.technology |
|
|
| ms.topic | article | |
| helpviewer_keywords |
|
|
| ms.assetid | 514cde76-f981-474e-8b40-9493619f899c | |
| caps.latest.revision | 16 | |
| author | BillWagner | |
| ms.author | wiwagn |
This example declares an interface, IDimensions, and a class, Box, which explicitly implements the interface members getLength and getWidth. The members are accessed through the interface instance dimensions.
[!code-csharpcsProgGuideInheritance#8]
-
Notice that the following lines, in the
Mainmethod, are commented out because they would produce compilation errors. An interface member that is explicitly implemented cannot be accessed from a class instance:[!code-csharpcsProgGuideInheritance#45]
-
Notice also that the following lines, in the
Mainmethod, successfully print out the dimensions of the box because the methods are being called from an instance of the interface:[!code-csharpcsProgGuideInheritance#46]
C# Programming Guide
Classes and Structs
Interfaces
How to: Explicitly Implement Members of Two Interfaces