日期:2014-05-18 浏览次数:21157 次
List<int> value = new List<int>(4); //此时 Count:0 Capacity: 4 for (int i = 1; i <= 5; i++) { value.Add(i); } //此时 Count:5 Capacity: 8 value.TrimExcess(); //此时 Count:5 Capacity: 5 //remove an item value.RemoveAt(4); //此时 Count:4 Capacity: 5 value.TrimExcess(); //此时 Count:4 Capacity: 5---------------[color=#FF0000]Capacity为什么不是4呢?请高手指点[/color] //remove another item value.RemoveAt(1); //此时 Count:3 Capacity: 5 value.TrimExcess(); //此时 Count:3 Capacity: 3 value.Clear(); //此时 Count:0 Capacity: 3 value.TrimExcess(); //此时 Count:0 Capacity: 0