-2

I trying to calculate my string but I don't have any idea how to do that.

I want to do something like this:

string input = "2+2+2+2*5^2/2";
Console.WriteLine(Calculate(input));

I tried to use DataTable().Compute() but its dose not support many of operators.

2

1 Answer 1

0

You can use DataTable.Compute for that. this method computes the given expression on the current rows that pass the filter criteria.

You can read more about it here: https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable.compute?view=net-5.0

string input = "2+2+2+2*5^2/2";
string res = new DataTable().Compute(input, null).ToString();

Console.WriteLine(res);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.