3

i had asked earlier about the same kind of question but that was in java....
now for the knowledge, i want to know...

is it possible to run the one C# code using another C# code?

bcz i know C# is very powerful, so their might be some way to do this.

1
  • There is CodeDom namespace for this. Check this article Commented Jun 22, 2010 at 9:24

2 Answers 2

4

It's the same sort of deal:

  • Compile the code, e.g. using CSharpCodeProvider
  • Execute the code, e.g. using reflection

If you download Snippy from the C# in Depth web site, you can see a smallish example of this - basically you type in snippets of C# and it can compile and execute them for you.

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

Comments

4

That is ultimately a runtime feature; in MS .NET, CSharpCodeProvider is the closest you'll get at the moment, although they have mentioned possibly looking at the "compiler as a service" in the future.

If you're happy to use Mono, it already exists , with REPL example.

Usage (from here):

  // First setup the active using statements:
  Evaluator.Run ("using System;");

  Evaluator.Run ("Console.WriteLine (\"Hello, World\");

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.