这是我的班级,名称为“ Objek”。
public class Objek
{
public int id;
public int tipe;
public int bentuk;
public List<int> x { get; set; }
public List<int> y { get; set; }
public int xC { get; set; }
public int yC { get; set; }
public Color Warna { get; set; }
public Objek()
{
this.Warna = Color.Black;
this.x = new List<int>();
this.y = new List<int>();
}
public Objek(int tipe, int bentuk)
{
this.tipe = tipe;
this.bentuk = bentuk;
this.Warna = Color.Black;
this.x = new List<int>();
this.y = new List<int>();
}
}
然后在form1.cs中,我全局声明了此声明(在任何方法之外):
Objek temp = new Objek();
输入“ temp”的值后,将其存储到列表中:
List<Objek> Objek = new List<Objek>();
用Objek.Add(temp);
的问题是每当我改变元素的属性值中的一个(例如:Objek[0].Warna = Color.Red
)存储超过1“TEMP”对象,所有后Objek[0, 1, ..., n].Warna
也改变为红色。
有人可以解释一下我在这些代码中的错误吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句