2

Possible Duplicate:
using eval in Java

In javascript i can call a function using eval like :

eval('my_javascript_code;')

Is there anything like that in C# or JAVA which lets me run C# or JAVA code?

String time = Eval("My csharp code");

Or Am I completely off the track?

1
  • You can use Beanshell in Java. This produces a scripting library for Java and is used in many debuggers for ad hoc expressions. However, use of "eval" or dynamic code is discouraged in Java (and I suspect most languages it's not a good idea) Commented Dec 5, 2012 at 10:19

1 Answer 1

0

There is no direct analogue - there is no built in function that will take a string and run it as executable code.

You can use the different reflection options of either platform to execute code dynamically. These include creating classes in code, compiling them and executing them and is not easy or fast.

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

3 Comments

Not easy or fast indeed. Last I tried this in C#, it took over 100 milliseconds to execute a trivial arithmetic operation in this fashion.
@Downvoter - care to comment?
Not my downvote, but I guess the answer was a bit vague. Maybe add some links, or searchable terms like "runtime compiling" and "dynamic assembly loading"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.