Hello, i am new to using C# and I was wondering how if i set some variable in a from how i can transfer them back to the main method?

for example if i have:

public partial class MyInputForm : Form
         String name;
            Int ref_no;

        public ..... FORM IMPLEMENTATION

as part of Form1.cs and i want to use them in static void main in program.cs. How would I achieve this?


You can use static variables.
In your MyInputForm class, declare a variable as follows:

public static String name;

This variable can now be accessed from anywhere/any class within the application using the following:


The current value of the variable 'name' can be accessed using this.

Hope this helps!

Thank you, you have solved my problem!