【问题标题】:Explicit interface implementation in VB.NETVB.NET 中的显式接口实现
【发布时间】:2009-10-16 09:48:05
【问题描述】:

如何在VB.NET中实现显式接口实现?

【问题讨论】:

    标签: .net vb.net


    【解决方案1】:

    由于others 拥有said,因此将例程设为私有,它会强制客户端通过接口调用。

    再多说一句。 C# 中的显式接口实现还允许程序员inherit two interfaces that share the same member names and give each interface member a separate implementation。在 VB.Net 中,这很容易,因为实现方法的名称可以与接口名称不同。

    Function ICanUseAnyNameILike() As String Implements IFoo.Bar
    
    Function ItsTotalAnarchy() As String Implements IFoo2.Bar, IFoo3.ItsMadnessReally
    

    【讨论】:

    • 从这里开始,我将在我的项目中使用IFoo3.ItsMadnessReally 作为接口方法。
    【解决方案2】:

    将方法设为私有。

    【讨论】:

      【解决方案3】:

      只需声明子/函数Private:

      Private Function Bar() As String Implements IFoo.Bar
      

      【讨论】:

        猜你喜欢
        • 2016-03-10
        • 1970-01-01
        • 1970-01-01
        • 2012-04-23
        • 2013-04-12
        • 1970-01-01
        • 1970-01-01
        • 2012-03-01
        • 1970-01-01
        相关资源
        最近更新 更多