vendredi 24 mars 2017

Dynamically execute string as code in C#

I need to convert string to executable code. The string is in foreach statement.

foreach (InsuredItem _i in p.InsuredItems)
{
    string formula = "(_i.PremiumRate/100)*SumAssured";
    _i.Premium = (Execute formula);
}

The formula is loaded from setup. this is just a demonstration. I need to execute the string in each loop. Thanks.





Aucun commentaire:

Enregistrer un commentaire