C#?д?List????????
???????????? ???????[ 2016/3/28 11:33:45 ] ??????????????????? .NET
?????????????????List??????????ù????????????п????List??????????????????????10??????List??????????????????????α仯???????MSDN?????List??Capacity??????????????????????????????????????С?????Capacity??????List????????μ???????????????????????????????????棬???????????????????????Capacity ??????List?????????????????????????????????棬?????????Ч??????????????????
?????????????List<T> list = new List<T>();????????List???????.Net Framework??????????????????????????list???????????????????list???ж???item????????????list???????item???list????????洢4??Item????洢??????Capacity??4????????????????????item????????Capacity????8??????list????????????????Capacity????????????????????·?????棬??????????????item???Capacity????12????16??????list?????????????????????item??????????????????????е?item??????????????????μ???檔
??????????????????list?????????????????list?????????????棬???????????????????????棬????????????????????????????
??????????????Capacity??????list???????????????????TrimExcess()????????δ??????檔
class Program
{
static void Main(string[] args)
{
List<Part> parts = new List<Part>();
Console.WriteLine("
Capacity: {0}"?? parts.Capacity);
parts.Add(new Part() { PartName = "crank arm"?? PartId = 1234 });
parts.Add(new Part() { PartName = "chain ring"?? PartId = 1334 });
parts.Add(new Part() { PartName = "seat"?? PartId = 1434 });
parts.Add(new Part() { PartName = "cassette"?? PartId = 1534 });
parts.Add(new Part() { PartName = "shift lever"?? PartId = 1634 });
Console.WriteLine();
foreach (Part aPart in parts)
{
Console.WriteLine(aPart);
}
Console.WriteLine("
Capacity: {0}"?? parts.Capacity);
Console.WriteLine("Count: {0}"?? parts.Count);
parts.TrimExcess();
Console.WriteLine("
TrimExcess()");
Console.WriteLine("Capacity: {0}"?? parts.Capacity);
Console.WriteLine("Count: {0}"?? parts.Count);
parts.Clear();
Console.WriteLine("
Clear()");
Console.WriteLine("Capacity: {0}"?? parts.Capacity);
Console.WriteLine("Count: {0}"?? parts.Count);
Console.Read();
}
}
public class Part
{
public string PartName { get; set; }
public int PartId { get; set; }
public override string ToString()
{
return "ID: " + PartId + " Name: " + PartName;
}
}
?????????list??Capacity??TrimExcess()??????????????????????????????????????У?????????????????????
????1.??????????????List????????????????Item????????????????List<T>????Capacity??????????????List???????public List(int capacity);?????
????2.???????????list??remove??????????????list????????????????????????????????????????????TrimExcess???????????????檔
?????????????list??????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11