W
W
WS_Gleb_Sirius2021-04-23 20:28:56
.NET
WS_Gleb_Sirius, 2021-04-23 20:28:56

Executing a string as code?

We need to make a calculator that calculates mathematical expressions in many steps (without cos() tan(), etc.). The idea is this: the user enters an example in Gui written in WPF, and C# reads it and displays the answer. Let's say the user enters 2+2*2 and you want to display the answer, that is, the number 6.
How in C# to execute the data of a variable of type string as code? If not, then how to execute list data with string elements as code, if each number or action is a separate list element?

If the user can't enter his code in C# when the program is running, then how can you write a calculator?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-04-23
@vabka

https://ru.wikipedia.org/wiki/Sorting_algorithm...
https://ru.wikipedia.org/wiki/Reverse_Polish_Notation

R
Roman, 2021-04-25
@yarosroman

https://stackoverflow.com/questions/821365/how-to-...
Expression trees to help you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question