2010-08-05 35 views
0

我有一個基類foo將在相似但略有不同功能的多個子類中使用的內部函數:VB.NET:聲明一個基類非重寫

Public MustInherit Class foo 
    Public Function bar1() as Something 
     ''// Perfectly OK to change what this method does 
    End Function 

    Public Function bar2() as Something 
     ''// Does a very specific thing I don't want changed ever, 
     ''// but this function must be inherited 
    End Function 
End Class 

如何獲得編譯器生成一個錯誤,當bar2()被子類覆蓋?

回答

3

指定函數定義的關鍵字NotOverridable

Public NotOverridable Function bar2() As Something 
    ''// Does a very specific thing I don't want changed ever, 
    ''// but this function must be inherited 
End Function 
+0

這是那些日子之一......非常感謝你。 – 2010-08-05 21:34:27

+0

@Heather沒問題:) – Andy 2010-08-06 11:16:31

1
+0

*(嫌額頭)*谷歌卻一無所獲我。謝謝! – 2010-08-05 21:26:46