Оптимизация калькулятора - Visual Basic .NET
Формулировка задачи:
Здравствуйте! Прошу помощи!
Совсем недавно начал программировать. И решил создать калькулятор.
Вот код:
Как его можно оптимизировать? Заранее спасибо!
Решение задачи: «Оптимизация калькулятора»
textual
Листинг программы
Public Enum Operations
Plus
Minus
End Enum
Private actions As New Dictionary(Of Operations, Func(Of Integer, Integer, Integer))() From { _
{Operations.Plus, Function(x, y) x + y}, _
{Operations.Minus, Function(x, y) x - y} _
}
Public Function Math(x As Integer, y As Integer, operations As Operations) As Integer
Return actions(operations)(x, y)
End Function
Public Function Math(x As String, y As String, operations As Operations) As Integer
If x = [String].Empty OrElse y = [String].Empty Then
Throw New Exception("X or Y is Empry!")
End If
Return actions(operations)(Convert.ToInt32(x), Convert.ToInt32(y))
End Function