2
私はインタフェースの要素を持っています。私は適切な機能を使いたい。機能の実装の(IF)、それは常にインタフェースは基本クラスの継承が必要です
インタフェース
Public Interface I
Function F() As Boolean
End Interface
基本クラスは、基本クラスを使用してインタフェースI
Public MustInherit Class B
Implements I
Public Overridable Function F() As Boolean Implements I.F
Return True
End Function
End Class
のクラスの実装基底クラスの関数を使用しているため れますが、オブジェクトとして使用する
Public Class C1
Inherits B
Public Overloads Function F() As Boolean
Return False
End Function
End Class
Public Class C2
Inherits B
End Class
サンプル
Sub Main()
Dim x As I
x = New C1
If x.F Then
Console.WriteLine("c1 = true")
Else
Console.WriteLine("c1 = false")
End If
x = New C2
If x.F Then
Console.WriteLine("c2 = true")
Else
Console.WriteLine("c2 = false")
End If
Console.ReadLine()
End Sub
結果:
c1 = true
c2 = true
c1は彼のために独自の関数 "F" でfalseにする必要があります。あなたはそれをオーバーロードしたくない