C#動態(tài)編譯并執(zhí)行字符串樣例
本文實例為大家分享了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(); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
欄 目:C#教程
下一篇:C#實現(xiàn)微信結(jié)合百度api獲取當(dāng)前用戶地理位置的方法
本文標(biāo)題:C#動態(tài)編譯并執(zhí)行字符串樣例
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5594.html
您可能感興趣的文章
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并打開的方法
- 01-10C#動態(tài)創(chuàng)建button的方法
- 01-10WinForm實現(xiàn)窗體最大化并遮蓋任務(wù)欄的方法
- 01-10C#動態(tài)創(chuàng)建Access數(shù)據(jù)庫及密碼的方法
- 01-10C#實現(xiàn)簡單合并word文檔的方法
- 01-10C#獲取動態(tài)生成的CheckBox值
- 01-10C#中DataGridView動態(tài)添加行及添加列的方法
- 01-10實現(xiàn)ASP.NET無刷新下載并提示下載完成的開發(fā)思路
- 01-10C#類的多態(tài)性詳解
- 01-10C#實現(xiàn)讀取DataSet數(shù)據(jù)并顯示在ListView控件中的方法


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現(xiàn)txt定位指定行完整實例
- 01-10WinForm實現(xiàn)仿視頻播放器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10C#中split用法實例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 04-02jquery與jsp,用jquery