日期:2014-05-18  浏览次数:20751 次

Arraylist remove的问题,大家帮一下
初学者的一个问题
  建了一个类
  class block
  {
  string id;
  Color dcolor;
  public block(string uid,Color ucolor)
  {
  id = uid;
  dcolor = ucolor;
  }
  }
执行以下代码
  ArrayList bt = new ArrayList();  
  private void button1_Click(object sender, EventArgs e)
  {
  block b= new block("1000",Color.Red );
  bt.Add(b);
  label1.Text = bt.Count.ToString ();
  }
  private void button2_Click(object sender, EventArgs e)
  {
  block b = new block("1000", Color.Red);
  bt.Remove(b);
  label1.Text = bt.Count.ToString ();
  }
为什么我移除不掉Arraylist里的项呢?

------解决方案--------------------
给block实现Equals和GetHashCode方法