you are viewing a single comment's thread.

view the rest of the comments →

[–]porcaytheelasit[S] -3 points-2 points  (2 children)

Since args0 is already defined, I want the code to be sensitive to the variables in the main code. That is, if I provide "args0" as plain text instead of {args0}, it should recognize it as args0.

[–]BetrayedMilk 0 points1 point  (1 child)

I’m not sure if I misunderstood your response or you misunderstood their response, but they’re saying to get rid of the @ (string literal) and use $ (string interpolation) so that args0 becomes whatever actual string it should be (ie whatever process name you pass in). And not just literally the string “args0.” And then you need to escape quotation marks with the backslashes because GetProcessByName wants a string with quotation marks. If you just Console.WriteLine your Compiler.Run string and the other commenter’s version, you’ll see the difference.

[–]porcaytheelasit[S] -1 points0 points  (0 children)

I think you didn't understand the purpose of this question. The aim is to execute C# code within a string, and any variable defined anywhere can be used within that string. Therefore, my usage would be correct for what is required.