private void button1_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Text=" int a=3\n int b=3;\n int c=a+b;\n this.richTextBox2.Text=c.toString();";
}private void button2_Click(object sender, System.EventArgs e)
{
//这里要显示richTextBox1里所生成的代码的值,就是在richTextBox2显示C的值
}望能给出实现代码,机器上没装MSDN~~
{
this.richTextBox1.Text=" int a=3\n int b=3;\n int c=a+b;\n this.richTextBox2.Text=c.toString();";
}private void button2_Click(object sender, System.EventArgs e)
{
//这里要显示richTextBox1里所生成的代码的值,就是在richTextBox2显示C的值
}望能给出实现代码,机器上没装MSDN~~
解决方案 »
- 请问WPF为什么用VS2010 把断点放到Page的任意位置再debug就会假死?
- winform 继承问题
- C#编译exe时要添加SQLserver数据库文件的问题
- C#与C#.NET
- 请问这个windows console 控制台效果怎么实现?
- 将table1的数据导入table2中,不用DataSet,直接导,table1与table2的字段完全相同
- 把一个Hashtable转换为byte[],然后从byte[]转换回来
- 如何让FORM2在FORM1中显示
- vs.net安装出现的问题
- 正在学C#一个简单的问题
- 求助!C#对word的操作,将datagrid的数据保存的word文档的模板中!
- 请问各位,如何重画listview的column header(求源码,高分酬谢,谢绝灌水)?
http://teach.spaceedu.com/A200508/2005-08-07/186389.html
http://www.yomi.cn/computer/A200508/2005-08-07/186389.html另外可以发消息与飞刀联系探讨下:
http://message.csdn.net/SendMessage.aspx?To=aspcn
C# Script (missing puzzle piece)
http://www.codeproject.com/csharp/cs-script_for_CP.asp
** 文件名: Eval.cs
** Copyright (c) 1999 -2003
** 创建人: Phoenix
** 创建日期:
** 修改人:
** 修改日期:
** 描 述: 获取字符串所表示的逻辑意义
** 版 本:1.0
******************************************************************/using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Reflection;public class Eval
{
static object GetValue( string value )
{
string codeSnippet = "using System; " + "\r\n" +
"namespace CzG {" + "\r\n" +
" public class Eval" + "\r\n" +
" {" + "\r\n" +
" public Eval(){} " + "\r\n" +
" public object GetValue()" + "\r\n" +
" {" + "\r\n" +
" return " + value + ";" + "\r\n" +
" }" + "\r\n" +
" } }";CodeSnippetCompileUnit unit = new CodeSnippetCompileUnit( codeSnippet ); ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters para = new CompilerParameters();
para.ReferencedAssemblies.Add( "System.dll" );
para.GenerateInMemory = true;
para.GenerateExecutable = false;
para.OutputAssembly = "Eval.dll";Assembly asm = compiler.CompileAssemblyFromDom( para , unit ).CompiledAssembly;Type type = asm.GetType( "CzG.Eval" );
MethodInfo mi = type.GetMethod( "GetValue" , BindingFlags.Public | BindingFlags.Instance ); object obj = asm.CreateInstance( "CzG.Eval" );return mi.Invoke( obj , null );
}
}一个例子
通过CodeDom动态生成程序集,通过反射来调用程序集里的东西。
CodeDom的功能是很强大的。楼主还是装个MSDN吧。
{
static object GetValue(string value)
{
string codeSnippet = "using System; " + "\r\n" +
"namespace CzG {" + "\r\n" +
" public class Eval" + "\r\n" +
" {" + "\r\n" +
" public Eval(){} " + "\r\n" +
" public object GetValue()" + "\r\n" +
" {" + "\r\n" +
" return " + value + ";" + "\r\n" +
" }" + "\r\n" +
" } }"; CodeSnippetCompileUnit unit = new CodeSnippetCompileUnit(codeSnippet); ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters para = new CompilerParameters();
para.ReferencedAssemblies.Add("System.dll");
para.GenerateInMemory = true;
para.GenerateExecutable = false;
para.OutputAssembly = "Eval.dll"; Assembly asm = compiler.CompileAssemblyFromDom(para, unit).CompiledAssembly; Type type = asm.GetType("CzG.Eval");
MethodInfo mi = type.GetMethod("GetValue", BindingFlags.Public | BindingFlags.Instance); object obj = asm.CreateInstance("CzG.Eval"); return mi.Invoke(obj, null);
}
static void Main()
{
Console.WriteLine(Eval.GetValue("125 -23"));
Console.WriteLine(Eval.GetValue("125<23"));
}
}
仅供参考 相信这是你要想要的
strTemp.Replace("b",b);strResult = Evaluator.EvalToString(strTemp);strResult应该就是计算的结果。