要编写哪个代码块以及在哪里到达和分配?大家好,对于这个基本问题很抱歉,但如果你能在下面解释一些问题,我会很高兴。谢谢。
namespace forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// in thic code block what kind of things can i write or im allowed to write? Q1
}
Form2 frm2 = new Form2(); // why should i write this line (since i already added form2 to my project as seen in the picture) ![enter image description here][1]to see frm2.Show(); in button1_Click part? Q2
//what happens in the background (from the compiler point of view) when i do Form2 frm2 = new Form2();? Q3
frm2.Show(); // why cant i reach frm2 in here? i just declared above. Q4
//just like that
int number1; // i declare number variable in here
number1= 5; // and why cant i assign number in here?
// what kind of things can i write or allowed to write in this block ? Q5
// i sometimes confuse where i need to start writing the code or where i need to write or in which block ?
public int number2;
// ok now lets say i put a button on the form and when i double click it generated the code down below
//and now lets look in that code block
private void button1_Click(object sender, EventArgs e)
{
// ok now we are in this block and now it see when i write
frm2.Show();
//or
//it see when i write
number1 = 5;
//ok now lets look at number1 and number2 what changes when i write public int and just int without public? Q6
}
}
}