0

I would like to execute some code from string. Could somebody tell me if that's possible?

using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable<int> testArray = Enumerable.Range(1, 100);
            string testCommand = "testArray.Where(i => i % 2 == 0)";

            ???
            IEnumerable<int> result = Exucute(testCommand); //return only even numbers  
            ???
        }
    }
} 

Takeren
  • 45
  • 6
  • 5
    Does this answer your question? [Is it possible to dynamically compile and execute C# code fragments?](https://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments) and [How to execute code that is in a string](https://stackoverflow.com/questions/4800267/how-to-execute-code-that-is-in-a-string) –  May 28 '21 at 21:31
  • My solution for this problem was using some fancy library. https://eval-expression.net – Takeren Jun 08 '21 at 21:05

0 Answers0