Hi I am learning C#.
I created two forms. Form1, Form2.
Inside the program.cs -> static class Program -> static void Main() -> I am doing Application.Run(new Form1());
I have a public variable in Form1. That is "public static int myCode";
Inside the Form1-> There is a button -> button1.
I wrote a code like, button1_click(... ..)-> Form2 frm = new Form2(); frm.Show();
But here inside the form2 i want to show the value of Form1's variable that is "myCode". I am not able to access it. How to get that value to Form2.
I tried to have a public static function and tried to return the value of the "myCode". But it is showing error "not all codepaths return a value"
Then I tried to change some thing in Program.cs like create a Form1's object -> Form1 frm; and then inside main() -> frm = new Form1(); and then wrote that Application.Run(frm);
But here also i am getting some other error.
How can i access myCode from first form to Form2? Please share answer. Thanks in advance.