0

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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by akkkk
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.