Skip to content

Getting started

amomra edited this page Apr 20, 2015 · 2 revisions

Getting started

The first thing to do is to download and install the muParserNET library into your project. This can be done through NuGet by right-clicking the project and selecting the option "Manage NuGet Packages..." in Visual Studion 2013.

Example code

Using muParserNET is pretty straightforward as you can see in the following example. The sample defines a parser variables ("a") and adds a user defined functions named "MyFunc". When using the parser make sure that you don't forget to catch possible exceptions of type ParserError.

usingmuParserNET;publicclassExample{// Function callbackpublicstaticdoubleMySqr(doubleval){returnval*val;}publicstaticvoidMain(String[]args){try{Parserp=newParser();ParserVariablea=p.DefineVar("a",1);p.DefineFun("MySqr",MySqr,true);p.Expr="MySqr(a)*_pi+min(10,a)";for(inti=0;i<100;++i){a.Value=i;// Change value of variable aConsole.WriteLine(p.Eval());}}catch(ParserErrore){Console.WriteLine(e.Message);}}}

Clone this wiki locally