How to store a code sentence on a variable?

  • Thread starter Thread starter Artificer
  • Start date Start date
A

Artificer

Allow me to explain my question. I would like create a function in
which one of it sentences will be decided at run time.


Something like

String MySentence= "int x=0;"

Public void MyFunction (String MyCode)

{

Execute (MyCode);

}


Here "Execute" is a fictitious reserved word that will read the string
and execute the code inside it.



There is something like "Execute" in C# ?
 
Artificer,

No, there isn't. Granted, you could dynamically compile the code and
load it, but that's not even worth it.

What you should do is define an interface that has methods on it which
have a defined set of inputs and outputs, and then execute different
implementations of it depending on your needs.

Hope this helps.
 
Back
Top