今天遇到的一个奇怪的vb.net问题
事情是这样的,我写了一个类MyCollection继承自System.Collection.CollectionBase类,CollectionBase类里有方法RemoveAt和OnRemove,它们的定义如下:
Public Overridable Sub RemoveAt( ByVal Index As Integer ) Implements IList.RemoveAt
Protected Overridable Sub OnRemove( ByVal index As Integer, ByVal value As Object )
在我的继承类MyCollection中Overrides了这两个方法
Public Overrides Sub RemoveAt(ByVal index As Integer)
......
End Sub
Protected Overrides Sub OnRemove(index As Integer, value As [Object])
......
End Sub
在编译时方法2没有任何问题,方法1报错 'Public Overrides Sub RemoveAt(index As Integer)' cannot override 'Public Overridable NotOverridable Sub RemoveAt(index As Integer)' because it is declared 'NotOverridable'.
上面的报错信息中基类的RemoveAt的修饰符成了"Overridable NotOverridable",令人费解,这两个修饰符是不应该同时出现的,而且这和基类的定义也不同。
最后将方法1改为
Public Shadows Sub RemoveAt(ByVal index As Integer)
......
End Sub
通过了编译。