Class Program1 Shared Sub Main() Dim リンゴ As New 分数(1, 2) Dim ミカン As New 分数(1, 2) Dim あの果物 As 分数 = リンゴ MsgBox( _ "リンゴの個数:" & リンゴ.ToString() & vbCrLf & _ "ミカンの個数:" & ミカン.ToString() _ ) If リンゴ = ミカン Then MsgBox("どちらも 1/2 個なので、値の比較としては True") End If If リンゴ Is ミカン Then MsgBox("ここが実行されることは無い") Else MsgBox("両者は、異なる'物(object)'であるため、参照の比較としては False") End If If リンゴ Is あの果物 Then MsgBox("'あの果物' は 'リンゴ' への参照なので、参照比較は True") End If End Sub End Class Class 分数 'Strucure ではなく、Class にしています。 Public 分子 As Integer Public 分母 As Integer Public Sub New() MyClass.New(0, 1) End Sub Public Sub New(ByVal 分子 As Integer, ByVal 分母 As Integer) Me.分子 = 分子 Me.分母 = 分母 End Sub Shared Operator =(ByVal x As 分数, ByVal y As 分数) As Boolean Dim f1 As Double = x.分子 / x.分母 Dim f2 As Double = y.分子 / y.分母 Return f1 = f2 End Operator Shared Operator <>(ByVal x As 分数, ByVal y As 分数) As Boolean Return Not (x = y) End Operator Public Overrides Function ToString() As String Return String.Format("{0:#,0}/{1:#,0} (={2:#,0.0000})", 分子, 分母, 分子 / 分母) End Function End Class