Dynamically Executing Code in .NET – Compiling C# Code at Runtime

In a recent project, I was confronted with a necessity to change some parts of code algorithms very quickly because government changes. Updating the entire application was not an option, so I decided to implement a feature to allow the application to download small pieces of code that changed frequently to use it.

The application perform some tax math that changes in a monthly basis. Now I can pull only changed code and use it to perform the routine.

To do this I have used the CSharpCodeProvider class from Dotnet framework, that allow us to use C# code as scripting language in my C# application.

In this article I am creating a simple application that have two listbox, the source have all country names and the target will be populated from our script code.