O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Explicit Interface Member Implementations

Interfaces are great because they define a standard way for types to communicate with each other. However, this flexibility comes at the cost of compile-time type safety because most interface methods accept parameters of type System.Object or return a value whose type is System.Object. Look at the very common IComparable interface:

public interface IComparable {
   Int32 CompareTo(Object other);
}

This interface defines one method that accepts a parameter of type System.Object. If I define my own type that implements this interface, the type definition might look like this:

struct SomeValueType : IComparable { private Int32 x; public SomeValueType(Int32 x) { this.x = x; } public Int32 CompareTo(Object other) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required