List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };

 

            //这里用foreach时,会出错,主要是foreach在检索的时候,它的数组不能变 for循环的就可以

            //foreach (int i in list)

            //{

            //    MessageBox.Show(i.ToString());

            //    list.Remove(i);

            //}

 

            for (int j = 0; j < list.Count; j++)

            {

                MessageBox.Show(list[j].ToString());

                list.Remove(list[j]);

                j--;

            }

相关文章: