Share via

Microsoft.CodeAnalysis.CSharp.Scripting - C#

Hemanth B 886 Reputation points
2021-09-11T17:06:29.4+00:00

Hi, I am using the nuget package Microsoft.CodeAnalysis.CSharp.Scripting for my expression evaluator in C#. Almost everything is getting evaluated except few, like "(1-32) * (5/9)" which is giving 0 as result and "(9/5)" which is giving 1 as result instead of 1.8. Why is this happening?
I am using this code:

    var result = CSharpScript.EvaluateAsync<double>("(1- 32) (5/9)").Result;

Also when I provide the input without brackets in between or at the end like (1- 32) (5/9, it is throwing an exception saying ")" expected. How do I automatically add necessary brackets?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.