我有一个控件可以覆盖 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/