0

I am making a mathematical Integration app in xaml and C# and for that I need to cast the user's input string representing a lambda expression in to a lambda expression or a function delegate. Is there any way to do so?

1 Answer 1

1

You can't directly cast a string to a Lambda expression in C#. You'll need to compile it somehow into executable code. There are several possibilities:

Depending on the complexity of the user's expressions, you might be better off interpreting them yourself.

Sign up to request clarification or add additional context in comments.

4 Comments

Don't forget Mono.CSharp, which has been around a lot longer than Roslyn! :)
Can you pls tell me how to do so using any one method as I am quite new to C#! I tried Mathos parser but this library cannot be downloaded for windows 8 store apps where as it works fine with windows form.
@user3411639: Without more information about what your user's input is, I can't give you more specific recommendations. I would suggest that you read up on the options, select one that you think would be appropriate, and try to implement your solution. If you run into trouble, post another question on Stack Overflow. Include in it information about the expected user input, what you expect your program to do, what you've done, and specific questions about how to make it work.
My input particularly is in the following format x=>x*x. This is a string and I want to convert it into a lambda exp or a delegate of type double would also suffice. Pls help

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.