How can I evaluate C# code dynamically?

后端 未结 16 2212
[愿得一人]
[愿得一人] 2020-11-22 03:37

I can do an eval(\"something()\"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?

An example of what I

16条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:17

    the correct answer is you need to cache all the result to keep the mem0ry usage low.

    an example would look like this

    TypeOf(Evaluate)
    {
    "1+1":2;
    "1+2":3;
    "1+3":5;
    ....
    "2-5":-3;
    "0+0":1
    } 
    

    and add it to a List

    List results = new List();
    for() results.Add(result);
    

    save the id and use it in the code

    hope this helps

提交回复
热议问题