How to store a code sentence on a variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Artificer

    #1

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

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: How to store a code sentence on a variable?

    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]
    - mvp@spam.guard. caspershouse.co m


    "Artificer" <eliezerfiguero a@gmail.com> wrote in message
    news:1135717672 .524867.222330@ g44g2000cwa.goo glegroups.com.. .[color=blue]
    > 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# ?
    >[/color]


    Comment

    Working...