using System; using System.CodeDom.Compiler; using System.IO; class Program { static void Main(string[] args) { // Create a CodeDomProvider CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); // Declare a set of compiler parameters CompilerParameters parameters = new CompilerParameters(); parameters.GenerateExecutable = true; parameters.OutputAssembly = "Example.exe"; // Compile the code CompilerResults results = provider.CompileAssemblyFromSource(parameters, @"using System; class Example { static void Main(string[] args) { Console.WriteLine(""Hello, world!""); } }"); // Display any errors generated by the compiler if (results.Errors.Count > 0) { foreach (CompilerError error in results.Errors) { Console.WriteLine(error.ErrorText); } } else { Console.WriteLine("Compilation succeeded."); } Console.ReadKey(); } }This example demonstrates how to create a CodeDomProvider and then use it to compile a small C# program that just prints out "Hello, world!" to the console. The System.CodeDom.Compiler namespace is part of the .NET Framework Class Library.