c# - 接口(interface)从 vb.net 到 c# 的转换

标签 c# .net vb.net interface

我有一个控件可以覆盖 protected GetService 方法并将其分配给 IServiceProvider 接口(interface):

Class MyControl
    Inherits Control
    Implements IServiceProvider

    Protected Overrides Sub GetService(t as Type) as Object Implements IServiceProvider.GetService
    End Sub

End Class

我正在努力将其转换为 C#。我试过隐式与显式,但我一定是语法错误。

最佳答案

你会这样做:

class MyControl : Control, IServiceProvider
{
     // Explicitly implement this
     object IServiceProvider.GetService(Type t)
     {
          // Call through to the protected version
          return this.GetService(t);
     }

     // Override the protected version...
     protected override object GetService(Type t)
     {
     }
}

也就是说,Control 已经实现了 IServiceProvider(通过 Component)。你真的可以这样做:

class MyControl : Control
{
     protected override object GetService(Type t)
     {
     }
}

关于c# - 接口(interface)从 vb.net 到 c# 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3840616/

相关文章:

c# - Mono.Cecil 中的 If/else 和 while 分支

xml - 在 Excel 上显示时,邮政编码会去掉前导零。导出到 excel 从 vb.net XML 到 XSLT 转换

c# - 获取扩展方法的被调用者名称

c# - 在分布式系统中组织事件的执行并避免死锁

c# - Int32 的 GetHashCode() 是如何实现的?

c# - 逐步将 WebForm VB Web 应用程序转换为 MVC C#

.net - 搜索字典键中的某些部分并更新其值

c# - 在另一个完成后运行 BackgroundWorker

.net - MongoDB事务?

c# - 在 EPiServer 中设置默认语言?