<Id*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
| Hi all,
| I'm new to c# and .net and I have a few questions I did not manage to
| find an answer to:
|
| 1. what is the equivalent to the "exec" command in python/lisp?
| meaning: a string is given as input and the function execute it as a C#
| expression
|
| 2. what is the equivalent to the "eval" command in python/lisp?
| meaning: a string is given as input and is parsed and evaluated as a C#
| expression
|
| 3. how do i pass functions as parameters to other functions or save
| them in a variable? i.e.:
| static bla(){/*do stuff*/}
| ...
| somthing = bla
| someFunction(bla)
|
|
| thank you in advance,
| Ido.
|
If you happen to run v2.0 of the framework, you might check this
http://www.microsoft.com/downloads/d...displaylang=en
if you need eval and exec using Python for .NET.
Note that C# is not the only language in .NET, so you can even use
JScript.NET if you need Eval and call it from C#.
Here is a sample.
[JScript.NET module jeval.js]
//comile with: jsc /t:library jeval.js
package Test
{
class JSApp
{
function DoEval(s : String)
{
var dt : Date;
eval("dt = new "+s+";");
print(dt);
}
};
}
[C# program usejeval.cs]
// Compile with : csc /r:jeval.dll,microsoft.jscript.dll usejeval.cs
using System;
namespace Test
{
class Tester
{
static void Main()
{
Test.JSApp js = new Test.JSApp();
js.DoEval("Date(1999, 3,9)");
}
}
}
Willy.