Method 1:
Use the Microsoft. Vsa Method
Code
String Expression = "var result: int = 0; result = 1? \ "Success \": \ "Failure \"";
Microsoft. JScript. Vsa. VsaEngine ve = Microsoft. JScript. Vsa. VsaEngine. CreateEngine ();
Console. WriteLine (Microsoft. JScript. Eval. JScriptEvaluate (Expression, ve ));
Method 2:
Use the eval method in Javascript.
Code
/// <Summary>
/// Reference the com component Microsoft Script Control
/// % SystemRoot % \ system32 \ msscript. ocx
/// <Param name = "Expression"> </param>
/// <Returns> </returns>
Public static string Eval (string Expression)
{
String strResult = null;
Try
{
MSScriptControl. ScriptControlClass jscript = new MSScriptControl. ScriptControlClass ();
Jscript. Language = "JScript ";
StrResult = jscript. Eval (Expression). ToString ();
}
Catch (Exception ex)
{
Debug. Fail (ex. Message );
}
Return strResult;
}