Execute the C# code in runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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