为什么要明确实现接口? [英] Why implement interface explicitly?

查看:157
本文介绍了为什么要明确实现接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,到底什么是好的用例明确地实现接口?

So, what exactly is a good use case for implementing an interface explicitly?

难道只有让使用该类的人不必看那些方法/智能感知属性?

Is it only so that people using the class don't have to look at all those methods/properties in intellisense?

推荐答案

如果您实现两个接口,都具有相同的方法和不同的实现,那么你必须明确地落实。

If you implement two interfaces, both with the same method and different implementations, then you have to implement explicitly.

public interface IDoItFast
{
    void Go();
}
public interface IDoItSlow
{
    void Go();
}
public class JustDoIt : IDoItFast, IDoItSlow
{
    void IDoItFast.Go()
    {
    }

    void IDoItSlow.Go()
    {
    }
}

这篇关于为什么要明确实现接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆