3

I need to run small snippets of C# code for educational purposes and for each execution, I should open the project (solution), delete existing code, type new code, build and compile, and then run the project. For example, for executing string.IsNullOrEmpty("something") I should follow all this procedure. I just thought of something like:

enter image description here

In which I can enter code snippets, click execute, and then see the result. Is there anyway to do that?

5 Answers 5

10

You didn't explicitly state if you're looking for guidance on implementing your own solution or what, but if you're open to using a third party utility then LINQPad is pretty much exactly what you're describing.

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

2 Comments

I'm not interested to create my own solution for this. I just want to know if there is any tool out there available or not? Thanks for the link, I'll try that. But it seems that this application only executes LINQ queries. I want something global. Something that can execute one-line expressions like "Source String".Replace("Source", "Target");
You can execute single lines of code in LinqPad, as well as write small programs. I use it frequently for bits and pieces of throw-away code - and only rarely (if ever) for writing Linq2SQL queries. Despite the slightly misleading name, LinqPad does exactly what you want.
1

Take a look at Snippet Compiler.

Not exactly what you're asking for, but from what I can tell it seems pretty close.

1 Comment

This is not exactly what I want (as it's really complex and puzzles newbies). But it's really close. Thanks!
0

There is also ideone which can run C# code, as well as a large number of other languages.

1 Comment

Interesting, but it doesn't seem to evaluate expressions - it seems to be just a wrapper around csc.exe.
0

There is also mono's csharp/gsharp:

see http://www.mono-project.com/CsharpRepl

Comments

0

Mono are doing the compiler as service stuff - this is what you are looking for: http://tirania.org/blog/archive/2010/Apr-27.html

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.