Queue<T>.TrimExcess 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
TrimExcess() |
如果這個數位小於目前容量的90%,請將容量設定為 Queue<T>中的實際項目數目。 |
TrimExcess(Int32) |
將 Queue<T> 物件的容量設定為指定的項目數。 |
- 來源:
- Queue.cs
- 來源:
- Queue.cs
- 來源:
- Queue.cs
如果這個數位小於目前容量的90%,請將容量設定為 Queue<T>中的實際項目數目。
public:
void TrimExcess();
C#
public void TrimExcess();
member this.TrimExcess : unit -> unit
Public Sub TrimExcess ()
備註
如果集合中不會新增任何新元素,這個方法可用來將集合的記憶體額外負荷降到最低。 不過,重新配置和複製大型 Queue<T> 的成本可能相當大,因此,如果清單超過 90% 的容量,則 TrimExcess 方法不會執行任何動作。 這可避免產生相對較小的收益的大型重新配置成本。
這個方法是 O(n
) 作業,其中 n
Count。
若要將 Queue<T> 重設為其初始狀態,請先呼叫 Clear 方法,再呼叫 TrimExcess 方法。 修剪空白 Queue<T> 會將 Queue<T> 的容量設定為預設容量。
另請參閱
適用於
.NET 10 和其他版本
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |