Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Execute the C# code in runtime
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
namespace RuntimeCompile
{
internal class Program
{
private static void Main(string[] args)
{
var code = "(5 + 3).ToString()";
var run = CSharpScript.RunAsync(code, ScriptOptions.Default).Result;
var result = (string)run.ReturnValue;
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment