Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (23 sloc) 2.13 KB
title ms.custom ms.date helpviewer_keywords ms.assetid
How to: Explicitly Implement Members of Two Interfaces - C# Programming Guide
seodec18
07/20/2015
inheritance [C#], explicitly implementing interface members
interfaces [C#], explicitly implementing with inheritance
8b402ddc-dff9-4869-89cb-d718c764e68e

How to: Explicitly Implement Members of Two Interfaces (C# Programming Guide)

Explicit interface implementation also allows the programmer to implement two interfaces that have the same member names and give each interface member a separate implementation. This example displays the dimensions of a box in both metric and English units. The Box class implements two interfaces IEnglishDimensions and IMetricDimensions, which represent the different measurement systems. Both interfaces have identical member names, Length and Width.

Example

[!code-csharpcsProgGuideInheritance#9]

Robust Programming

If you want to make the default measurements in English units, implement the methods Length and Width normally, and explicitly implement the Length and Width methods from the IMetricDimensions interface:

[!code-csharpcsProgGuideInheritance#10]

In this case, you can access the English units from the class instance and access the metric units from the interface instance:

[!code-csharpcsProgGuideInheritance#11]

See also

You can’t perform that action at this time.