You need to use CodeDOM.
Now, what you would do with it? If you want to execute some of its code from your host application, you would need to define some interface known to both host application and the application to be built, so you have to reference some assembly with appropriate API, which should better be the definition of some interfaces which I usually call "plug-in interface". Then you can use the assembly build via .NET reflection.
But let's make one step at a time. First you need to learn CodeDOM. This topic is pretty simple. You can start here:
Using the CodeDOM[
^].
Now, about using the assembly you build from the user's code via reflection: please see my past answers:
Dynamically Load User Controls[
^],
C# Reflection InvokeMember on existing instance[
^],
code generating using CodeDom[
^] (again, on CodeDOM).
But now, we are coming to the more difficult problem. The problem is: if a user can write code and compile the assembly and then load it in the process's memory, it can be done again and again. And it will create a memory leak. In .NET, there are no a way to unload a loaded assembly (the reasons are pretty obvious, safety, but it's not so easy to explain it; please see my past answers referenced below). The only way to unload some code is to create an extra application domain and later unload it with all its assemblies. But it means that your compiled assembly (plug-in) should be in this separate application domain and communicate with your host via IPC (application domains work in isolated address spaces).
This is all solvable, but you have to learn all related techniques. Please see the rest of my past answers on the topic, all referenced in this one:
Access a custom object that resides in plug in dll[
^].
I do have a sample application doing all that, but it is not yet published.
—SA