Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 2.11 KB

File metadata and controls

35 lines (28 loc) · 2.11 KB
title How to: Explicitly Implement Interface Members (C# Programming Guide)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
helpviewer_keywords
interfaces [C#], explicitly implementing
ms.assetid 514cde76-f981-474e-8b40-9493619f899c
caps.latest.revision 16
author BillWagner
ms.author wiwagn

How to: Explicitly Implement Interface Members (C# Programming Guide)

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.

Example

[!code-csharpcsProgGuideInheritance#8]

Robust Programming

  • Notice that the following lines, in the Main method, 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 Main method, successfully print out the dimensions of the box because the methods are being called from an instance of the interface:

    [!code-csharpcsProgGuideInheritance#46]

See Also

C# Programming Guide
Classes and Structs
Interfaces
How to: Explicitly Implement Members of Two Interfaces