title: C# Treat A Block Of Code As If It Were Written As Part Of A Method
body: <p>I've got an issue which I know how to solve in Python, but can't find any way to solve in C#. The issue is that I need a way to run a block of code inside a Method without hard coding that block of code into the method</p>
  <p>For example, the block of code could be simply &quot;return;&quot; or it could change variables within the method, but there are a near infinite number of possibilities for what this code could be so any kind of if statement or hard coding possibilities in is out of the question</p>
  <p>In python, the easiest way I can think of to do this would be using Eval:</p>
  <pre class="lang-py prettyprint-override"><code>def Function1():
    num = 10
    Eval(MysteryCode())
    num += 1
    return num
  
  def MysteryCode():
    return input(&quot;Write code here:  &quot;)
  
  print(Function1())
  </code></pre>
  <p>If you type &quot;return num&quot; as the input, it should return 10. If you wrote &quot;num += 1&quot;, it should print 12. I won't actually be taking input from the user, but it's roughly the same as what I'm looking for</p>
  <p>It also doesn't need to be in string format, any way to run a block of code in a method that isn't hard coded into that method works</p>
  <p>Sorry if this doesn't make much sense, I'm struggling to explain this properly :(</p>