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?

Thanks

Recommended Answers

All 2 Replies

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:

MyInputForm.name;

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

Hope this helps!

Thank you, you have solved my problem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.