0

I want to compile and run dynamically string variable and also access to this project forms and classes

private void btncompiler_Click(object sender, EventArgs e)
{
    String str;
    str = @"
    int a, b;
    a = 3;
    b = 5;
    textBox1.Text = (a + b).ToString()";

    //Compile str=>
}

I do this with CSharpCodeProvider but can't access to textBox1 and other controls on this class

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
ame teaser
  • 11
  • 2
  • Does this help: https://stackoverflow.com/questions/10980596/c-sharp-repl-outside-visual-studio. It's Roslyn-based – Flydog57 Sep 19 '21 at 04:44
  • 3
    "I want to compile and run dynamically string variable" - 9 times out of 10, this is the wrong approach. – Mitch Wheat Sep 19 '21 at 05:44
  • 4
    Yes, that seams to be [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem), could you descibe what is your main problem? – Leszek Mazur Sep 19 '21 at 05:49
  • My program has a chart on form. I want to read a file from program directory. each file has a formula and my data must calculate with this formula then put result to chart – ame teaser Sep 19 '21 at 06:08
  • 2
    Then you need a formula evaluation library. There are plenty of them for .NET. What you were trying so far was just one big security hole in your software. – Ondrej Tucny Sep 19 '21 at 12:49

0 Answers0