Shorter solution to if,else if,else if

前端 未结 6 1857
深忆病人
深忆病人 2021-01-06 08:58

I\'m looking for a way to shorten this code up and avoid repeating code and if statements. What I\'m doing is creating a calculator that searches strings for operators &quo

6条回答
  •  梦谈多话
    2021-01-06 09:50

    Shorten the code by grabbing the variables separately from doing the operation. This will not reduce your "if" statements, but it will drastically reduce the line numbers.

    Don't do multiple variables until you understand trees... I've never worked with them personally, but I think "expression trees" are what you'll be after. (note: I just checked on google, yep, Expression Trees)

提交回复
热议问题