private void button1_Click(object sender, System.EventArgs e)
        {
            if (this.checkedListBox1.CheckedItems.Count > 0)
            {
                this.listBox1.Items.Clear() ;
                foreach (string items in this.checkedListBox1.CheckedItems)
                {
                    this.listBox1.Items.Add(items.ToString ()) ;
                }
            }
            
                for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
                {
                    this.checkedListBox1.SetItemChecked ( i , false) ;
                }
            
        }
和下面的为什么不一样.        private void button1_Click(object sender, System.EventArgs e)
        {
            if (this.checkedListBox1.CheckedItems.Count > 0)
            {
                this.listBox1.Items.Clear() ;
                foreach (string items in this.checkedListBox1.CheckedItems)
                {
                    this.listBox1.Items.Add(items.ToString ()) ;
                }
            
            
                for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
                {
                    this.checkedListBox1.SetItemChecked ( i , false) ;
                }
            }
        }

解决方案 »

  1.   

    当然不一样啊 
    你的第一段代码  
    if 的条件成立的时候...所执行的代码  为  
    this.listBox1.Items.Clear() ;
                    foreach (string items in this.checkedListBox1.CheckedItems)
                    {
                        this.listBox1.Items.Add(items.ToString ()) ;
                    }第二段代码中 所执行的代码为   this.listBox1.Items.Clear() ;
                    foreach (string items in this.checkedListBox1.CheckedItems)
                    {
                        this.listBox1.Items.Add(items.ToString ()) ;
                    }
                
                
                    for (int i = 0 ; i < this.checkedListBox1.CheckedItems.Count ; i++)
                    {
                        this.checkedListBox1.SetItemChecked ( i , false) ;
                    }请注意 你所使用的  {  和  }
      

  2.   

    效果一樣,都需要 this.checkedListBox1.CheckedItems.Count > 0 
    this.checkedListBox1.SetItemChecked ( i , false) ;
    才會執行
    上面至少需用一次判斷this.checkedListBox1.CheckedItems.Count > 0
    下面至少需要二次判斷this.checkedListBox1.CheckedItems.Count > 0