开始接触C#一星期多了,不让用指针始终让人非常头疼。
今天碰到的是多窗口问题,网上查了个代码,不太懂:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
//form1:
public
partial
class
Form1 : Form
{
public
delegate
void
MyDel(
string
value);
public
event
MyDel txtzt;
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
Form2 f2 =
new
Form2(
this
);
//this这里说的是指针,伏笔
f2.Show();
}
}
//form2
public
partial
class
Form2 : Form
{
public
Form2(Form1 f1)
//Form1吗?你确定不是Form1*吗?刚才明明给的是指针呀
{
InitializeComponent();
f1.txtzt +=
new
Form1.MyDel(txtzt);
}
private
void
txtzt(
string
s)
{
this
.textBox1.Text = s;
}
}
|
按照我的理解,既然在Form2里可以直接修改Form1的内容,那只有指针才能做到的呀。
而偏偏C#不允许用指针(嘴上说不让用,难道背地里还是在用指针?)