实现接口隐式和显式是否有意义

实现接口隐式和显式是否有意义

本文介绍了实现接口隐式和显式是否有意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在攻读MS 70-515考试。在其中一个实践中,作者实现了隐式和显式的接口。显式实现只调用隐式实现。显式实现刚刚列出而没有解释。

I'm currently studying for my MS 70-515 exam. In one of the practices the author implements an interface both implicit as well as explicit. The explicit implementation just calls the implicit implementation. The explicit implementation is just listed without an explanation.

同时拥有接口的隐式和显式实现是否有意义?我认为显式实现是多余的(在这种情况下)。

Does it make sense to have both an implicit and an explicit implementation of the interface? I would think the explicit implementation is redundant (in this case).

public class PassTextBox : TextBox, IScriptControl
{
    public virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors()
    {
        var descriptor = new ScriptControlDescriptor(
            "AjaxEnabled.PassTextBox", ClientID);
        // ...
        return new ScriptDescriptor[] {descriptor};
    }

    IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
    {
        return GetScriptDescriptors();
    }
}

BTW,代码似乎运行得很好没有显式实现,因为隐式实现是公开的。

BTW, the code seems to run just fine without the explicit implementation, as the implicit implementation is public.

它涉及第9章,第2课,准确练习3。

It concerns MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4 Chapter 9, Lesson 2, Practice 3 to be precise.

推荐答案

显式实现似乎完全是多余的。

The explicit implementation seems to be totally superfluous.

我想不出一种方法可以把它称之为如果你把它留下来会有所作为。

I can't think of a way to call it where it would make a difference if you left it out.

有一个小的区别,隐式版本是虚拟的,意味着它可以被覆盖。将始终在此入口点调用显式版本。但由于它只调用虚拟成员,因此这里不使用差异。

There is one small difference, the implicit version is virtual meaning it could be overridden. The explicit version will always be called at this entry point. But since it only calls the virtual member that difference is not used here.

这篇关于实现接口隐式和显式是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:37