欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#動(dòng)態(tài)編譯并執(zhí)行字符串樣例

 更新時(shí)間:2020年11月17日 14:48:24   作者:王寶會(huì)  
這篇文章主要為大家詳細(xì)介紹了C#動(dòng)態(tài)編譯并執(zhí)行字符串樣例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下

using System;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
 
class Program
{
 public static void Main()
 {
  // The C# code to execute
  string code = "using System; " +
      "using System.IO; " +
      "public class MyClass{ " +
      " public static void PrintConsole(string message){ " +
      "  Console.WriteLine(message); " +
      " } " +
      "} ";
 
  // Compiler and CompilerParameters
  CSharpCodeProvider codeProvider = new CSharpCodeProvider();
  CompilerParameters compParameters = new CompilerParameters();
 
  // Compile the code
  CompilerResults res = codeProvider.CompileAssemblyFromSource(compParameters, code);
 
  // Create a new instance of the class 'MyClass'    // 有命名空間的,需要命名空間.類名
  object myClass = res.CompiledAssembly.CreateInstance("MyClass");
 
  // Call the method 'PrintConsole' with the parameter 'Hello World'
  // "Hello World" will be written in console
  myClass.GetType().GetMethod("PrintConsole").Invoke(myClass, new object[] {"Hello World" });
 
  Console.Read();
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論