下面的代码完全一样,只是一个是C#,另一个是VB.Net。C# 编译得很好,但 VB.Net 抛出警告:
由于 'Interface IObserver(Of In T)' 中的 'In' 和 'Out' 参数,接口 'System.IObserver(Of Foo)' 与另一个实现的接口 'System.IObserver(Of Bar)' 不明确
为什么 VB.Net 显示警告而不是 C#?最重要的是,我该如何解决这个问题?
Obs:我正在使用 .Net Framework 4 和 Visual Studio 2010 Ultimate。
VB.Net 代码:
Module Module1
Sub Main()
End Sub
Public Class Foo
End Class
Public Class Bar
End Class
Public Class Beholder
Implements IObserver(Of Foo)
Implements IObserver(Of Bar)
#Region "Impl"
Public Sub OnCompleted() Implements System.IObserver(Of Bar).OnCompleted
End Sub
Public Sub OnError([error] As System.Exception) Implements System.IObserver(Of Bar).OnError
End Sub
Public Sub OnNext(value As Bar) Implements System.IObserver(Of Bar).OnNext
End Sub
Public Sub OnCompleted1() Implements System.IObserver(Of Foo).OnCompleted
End Sub
Public Sub OnError1([error] As System.Exception) Implements System.IObserver(Of Foo).OnError
End Sub
Public Sub OnNext1(value As Foo) Implements System.IObserver(Of Foo).OnNext
End Sub
#End Region
End Class
End Module
C#代码:
class Program {
static void Main(string[] args) {
}
}
public class Foo { }
public class Bar { }
public class Beholder : IObserver<Foo>, IObserver<Bar> {
#region IObserver<Foo> Members
public void OnCompleted() {
throw new NotImplementedException();
}
public void OnError(Exception error) {
throw new NotImplementedException();
}
public void OnNext(Foo value) {
throw new NotImplementedException();
}
#endregion
#region IObserver<Bar> Members
public void OnNext(Bar value) {
throw new NotImplementedException();
}
#endregion
}