51 o'clock to a friend, he asked a little question, just write dozens of lines of code can be a good illustration of the problem. But the machine is not installed VS, had to do. When you come back, think about it, if you have an online c#ide. So the internet to check the relevant information, the whole out a simple online c#ide.
To do this, mainly to solve two problems, first, if the text box on the page to compile and execute the code, the second is if the program to run the results of the output on the Web page.
The first question is not difficult. NET already has ready-made C # compile class CSharpCodeProvider (or other language), then use CompilerParameters class as compile parameter, can easily realize.
The second question, in the simplest case, is to display the content of the Console.Write method output on the Web page. This is also very good to do, as long as the output statement before compiling a replacement, the output of the content to save to another place. When the run is over, take it out of the place.
The code implementation is as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Vsonline.framework
{
/**////<summary>
Custom Output Classes
</summary>
public class Consoler
{
Store all output
public static dictionary<string, consoler> outputs {get; set;}
Static Consoler ()
{
outputs = new dictionary<string, consoler> ();
}
Output Operation #region Output operation
Current output
Public list<string> Output {get; private set;}
Public Consoler ()
{
Output = new list<string> ();
}
public void Write (Object str)
{
Output.add (str. ToString ());
}
public void WriteLine (Object str)
{
Output.add (str. ToString () + "\ n");
}
#endregion
}
}