请帮帮忙,C#对多个实例里的属性进行动态操作?
classaa{publicinti=0;intget(){returni;}voidset(intvalue){this.i=value;}}我创建了多个实例aa1,a...
class aa
{
public int i = 0;
int get() {
return i;
}
void set( int value)
{
this.i = value;
}
}
我创建了多个实例aa1,aa2,aa3,aa4,添加到list列表中,我想对每个实例做不同的操作,但是我局部方法自动创建实例添加list(aa())到列表的,我怎么知道我要找的是哪个实例对象,或者是怎么做标记,才能得到对应的对象 展开
{
public int i = 0;
int get() {
return i;
}
void set( int value)
{
this.i = value;
}
}
我创建了多个实例aa1,aa2,aa3,aa4,添加到list列表中,我想对每个实例做不同的操作,但是我局部方法自动创建实例添加list(aa())到列表的,我怎么知道我要找的是哪个实例对象,或者是怎么做标记,才能得到对应的对象 展开
1个回答
展开全部
public Form1()
{
InitializeComponent();
for (int i = 1; i <= 3; i++)
{
PictureBox p = new PictureBox();
p.Name = "pictureBox" + i.ToString();
p.Size = new System.Drawing.Size(50, 50);
p.Top = 20;
p.Left = i * 60;
p.Click += F;
p.BackColor = Color.Red;
Controls.Add(p);
}
}
private void F(object sender, EventArgs e)
{
PictureBox p = sender as PictureBox;
MessageBox.Show(p.Name);
}
{
InitializeComponent();
for (int i = 1; i <= 3; i++)
{
PictureBox p = new PictureBox();
p.Name = "pictureBox" + i.ToString();
p.Size = new System.Drawing.Size(50, 50);
p.Top = 20;
p.Left = i * 60;
p.Click += F;
p.BackColor = Color.Red;
Controls.Add(p);
}
}
private void F(object sender, EventArgs e)
{
PictureBox p = sender as PictureBox;
MessageBox.Show(p.Name);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询