動態執行c#程式碼

Hey,Coder!發表於2024-11-15
  1. Roslyn
    安裝Microsoft.CodeAnalysis.CSharp.Scripting
    using Microsoft.CodeAnalysis.CSharp.Scripting;
    using Microsoft.CodeAnalysis.Scripting;
 string code = "int result = 1 + 2; Console.WriteLine(result);";

 var options = ScriptOptions.Default.WithImports("System");

 var script = CSharpScript.Create(code, options);

 script.RunAsync().Wait();

[參考]
https://blog.csdn.net/weixin_30802273/article/details/99274776

相關文章