0

Possible Duplicate:
How can I evaluate a C# expression dynamically?

Let me describe my issue in an example. There is a string variable in my program:

string func = @"
void printHello()
{
    Console.WriteLine(""Hello world!"");
}
";

Is there any method to let me call this printHello function?

Thanks for any replies.

5
  • 3
    that won't even compile. what are you trying to achieve? Commented Jul 21, 2012 at 15:56
  • 2
    Assuming he is looking for runtime evaluation of C# this is a dup question, stackoverflow.com/questions/53844/… Commented Jul 21, 2012 at 15:58
  • 1
    support.microsoft.com/kb/304655 Commented Jul 21, 2012 at 16:00
  • You need a \ in order to continue a string in a new line. But a "\n" will not be included. Commented Jul 21, 2012 at 16:02
  • And why would you like to write your own code inside a string??? Commented Jul 21, 2012 at 16:04

2 Answers 2

2

Look at the CS-Script, it's a open source C# Script execution engine

http://www.csscript.net/

Sign up to request clarification or add additional context in comments.

Comments

0

You can dynamically create and execute code using CodeDomProvider.

Look here for an example: http://blogs.msdn.com/b/digitalnetbizz/archive/2004/01/31/create-assembly-in-memory-and-run-it.aspx

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.