Hello to all. In short, I will tell you, there is an application on winforms. I create a button and make an event on button1___click. This button1_click is created in the public partial class Main class .

I also have another class Solve, variables with values ​​are described there (this.a1 = 3, this.a2 = 2).

Question: How to take values ​​from class Solve and apply them in inside button1_click?

    2 answers 2

    Well, one of the options is to implement the Solve class in the same namespace as the main class of the application, after the main class, and describe the Solve class variables as static, that is, belonging directly to the class itself. Example:

    namespace Lol { public partial class Form1 : Form { ... private void button1_Click(object sender, EventArgs e) { int solve_var = Solve.a; } ... } public class Solve { public static int a = 10; public static int b = 20; } } 
    • solve. (equals and referenceequals methods only) - marioxxx
    • and everything takes value, thank you. And why when entering textbox the value is 12, when outputting to excel in cell A0 displays "System.Windows.Forms.TextBox, Text: 12" - marioxxx

    Those. create an instance of a class? Then like this:

     Solve solve = new Solve(); 

    Along the way, create method (s) in this same Solve class, for example, getVar (), which (e) "give" this data and call it:

     solve.getVar(); 

    If only I understood correctly what was meant.

    • sorry not that ... - marioxxx