Your question is very vague, but I think I understand what it is you are asking.
The variable you are trying to change inside your ExeClass
is not defined in there, but locally in the Form1_Load
method.
To get it inside the ExeClass.p1
method, you will need to pass it in.
There are a few ways of doing this. But in this case I would recommend that you pass your local variable and then return the changed value.
Returning something from a method changes the method declaration:
public void p1() // Old
public int p1() // New
This allows you to return a int
value from it.
We also need to pass a value in (your local variable), which is done by changing the declaration a bit more:
public int p1(int value) { ...
Now, we got the value passed in to the p1
method, and we can change it:
public int p1(int value) {
value += 1;
return value;
}
Now when we call the function, the value will be returned, and you need to catch it:
private void Form1_Load(object sender, EventArgs e)
{
int i = 1;
ExeClass p1 = new ExeClass();
int j = p1.p1(i); // See that we pass the `i` variable in here and that we catch the return value in the `j` variable.
Console.WriteLine("Value is now {0}", j); // Will print : "Value is now 2"
}
Edit:
If you are asking if there is a way to execute c# code from a string, then you can take a look at this thread for a bit more info, but if you can avoid it, I would recommend to not do that...