最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#动态编译并执行字符串样例
时间:2022-06-25 07:49:52 编辑:袖梨 来源:一聚教程网
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
代码如下 | 复制代码 |
usingSystem; usingMicrosoft.CSharp; usingSystem.CodeDom.Compiler;
classProgram { publicstaticvoidMain() { // The C# code to execute stringcode ="using System; "+ "using System.IO; "+ "public class MyClass{ "+ " public static void PrintConsole(string message){ "+ " Console.WriteLine(message); "+ " } "+ "} ";
// Compiler and CompilerParameters CSharpCodeProvider codeProvider =newCSharpCodeProvider(); CompilerParameters compParameters =newCompilerParameters();
// Compile the code CompilerResults res = codeProvider.CompileAssemblyFromSource(compParameters, code);
// Create a new instance of the class 'MyClass' // 有命名空间的,需要命名空间.类名 objectmyClass = 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,newobject[] {"Hello World"});
Console.Read(); } } |
相关文章
- 植物大战僵尸3醋栗投手怎么样 醋栗投手介绍一览 10-16
- 明日方舟终末地工厂玩法怎么玩 工厂玩法介绍 10-16
- 鸣潮嘉贝莉娜毕业面板如何-嘉贝莉娜毕业面板属性一览 10-16
- 明日方舟终末地T0阵容怎么搭配 T0阵容搭配推荐 10-16
- 米姆米姆哈黎光雀怎么打 黎光雀打法教学 10-16
- 境界刀鸣护廷十三队哪个角色比较强 护廷十三队角色推荐一览 10-16