Public Class Calculator : Inherits Form
Private Delegate Function DelegateFormula(ByVal m As Double, ByVal n As Double) As Double
Private Formula As New Dictionary(Of String, DelegateFormula)() From {{"+", Function(m, n) m + n},
{"-", Function(m, n) m - n},
{"*", Function(m, n) m * n},
{"/", Function(m, n) m / n}
}
'Make Love Click
Private Sub WhenMakeLove(sender As Object, e As EventArgs) Handles btnPlus.Click, btnSubstract.Click, btnMultiply.Click, btnDivision.Click
Dim op As String = DirectCast(sender, Button).Tag
Dim dict = Formula.ElementAt((New Random).Next(0, Formula.Count - 1)) ' Rnd() As Single
txtResult.Text = "N/A"
If (("+-*/").Contains(op)) AndAlso (IsNumeric(txtA.Text) AndAlso IsNumeric(txtB.Text)) AndAlso (Not (op = "/" AndAlso CDbl(txtB.Text) = 0)) Then
txtResult.Text = Formula(op).Invoke(txtA.Text, txtB.Text)
End If
End Sub
End Class