471,306 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

How to store a code sentence on a variable?

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

Dec 27 '05 #1
1 1242
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Artificer" <el*************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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# ?

Dec 27 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sanjay | last post: by
18 posts views Thread by Marian F. | last post: by
12 posts views Thread by jackson.rayne | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.