How to store a code sentence on a variable?

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# ?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top