How to run a syntax inside a string?

Any advice on this

string method1="DoCopy(stdArray, resultArray)"

Is there anyway to run what is instructed in the string method1

Run[method1]

Thanks




Answer this question

How to run a syntax inside a string?

  • Milothicus

    Thanks Galin,

    Its good to know that I still can use it (ex Foxpro)



  • JerryW

    if you want to run external application use Process.Start Method

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

    If you want ot execute code in such way I highly recommend you to NOT use such approach as this will make application difficult to maintain and very dangerous especialy if string is entered by user



  • Chris Lorton

    Yes you can.

    I've done this (or more or less) in VB 2005, should work in C# as well (I just translated from VB 2005 to C#) :

    System.Type pageType = this.GetType();
    System.Reflection.MethodInfo myMethod = pageType.GetMethod("method1");
    myMethod.Invoke(this, null);

    It could be possible you have to attach the parameters where I've put the "null" (last line of code).

    Is this what you're looking for



  • JTai

    Thanks Reinout,

    Could be, I will try it!

    Many Thanks



  • How to run a syntax inside a string?