最新下载
热门教程
- 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(); } } | |
相关文章
- 12306候补订单成功率高吗-12306候补55%概率靠谱吗 02-12
- POKI小游戏免费在线畅玩-poki秒玩游戏入口网页版一键即玩 02-12
- 夸克网页版入口如何快速查找-夸克浏览器2026最新官网直达地址 02-12
- 抖音网页版能抢福袋吗-抖音网页版抢福袋攻略 02-12
- 秘塔猫AI写作官网入口-秘塔写作猫官网登录通道 02-12
- 火车票余票查询攻略-火车票购买软件推荐 02-12