Skip to content
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 helpviewer_keywords ms.assetid
How to: Explicitly Implement Members of Two Interfaces - C# Programming Guide
inheritance [C#], explicitly implementing interface members
interfaces [C#], explicitly implementing with inheritance

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.



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:


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


See also

You can’t perform that action at this time.