本文整理汇总了C#中Stack.TrimExcess方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.TrimExcess方法的具体用法?C# Stack.TrimExcess怎么用?C# Stack.TrimExcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.TrimExcess方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StackItemPopN
public static void StackItemPopN(ref Stack<MuftecStackItem> RuntimeStack)
{
MuftecStackItem Item1 = Shared.Pop(ref RuntimeStack);
for (int i = 0; i < (int)Item1.Item; i++)
{
Shared.Pop(ref RuntimeStack);
}
// Call TrimExcess in case we got rid of a lot of elements
RuntimeStack.TrimExcess();
}
示例2: Main
static void Main()
{
var stack = new Stack<int>();
stack.Push(1);
Console.WriteLine(stack);
stack.Push(2);
Console.WriteLine(stack);
stack.Push(3);
Console.WriteLine(stack);
Console.WriteLine("Last: {0}", stack.Peek());
Console.WriteLine("Count: {0}", stack.Count);
Console.WriteLine("Contains 2: {0}", stack.Contains(2));
Console.WriteLine("Capacity: {0}", stack.Capacity);
stack.TrimExcess();
Console.WriteLine("Capacity: {0}", stack.Capacity);
while (stack.Count != 0)
Console.WriteLine("Pop: {0}", stack.Pop());
Console.WriteLine("Count: {0}", stack.Count);
try
{
stack.Clear();
stack.Pop();
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
}
try
{
stack.Clear();
stack.Peek();
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
}
}
示例3: TestTrimExcessFunctionalityShouldNotTrimCapacity
public void TestTrimExcessFunctionalityShouldNotTrimCapacity()
{
var elementsToAdd = 930;
var stack = new Stack<int>();
for (int i = 0; i < elementsToAdd; i++)
{
stack.Push(i);
}
stack.TrimExcess();
Assert.AreEqual(elementsToAdd, stack.Count);
Assert.AreEqual(1024, stack.Capacity);
}
示例4: TestTrimExcessAfterClearStack
public void TestTrimExcessAfterClearStack()
{
var stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
stack.Clear();
stack.TrimExcess();
Assert.AreEqual(0, stack.Count);
Assert.AreEqual(0, stack.Capacity);
}
示例5: VoxelSetup
public static void VoxelSetup()
{
lock (clearedChunks)
{
if (clearedPlanes == null)
{
clearedPlanes = new Stack<SweepPlanePoint[,]>();
for (int i = 0; i < MAX_SWEEP_PLANES_IN_QUEUE; i++)
clearedPlanes.Push(new SweepPlanePoint[1, 1]);
clearedPlanes.TrimExcess();
}
int chunksForQueue = (int)Math.Ceiling(FARSettingsScenarioModule.VoxelSettings.numVoxelsControllableVessel * 0.034375); //2.2 / 64
if (MAX_CHUNKS_IN_QUEUE != chunksForQueue)
{
clearedChunks.Clear();
MAX_CHUNKS_IN_QUEUE = chunksForQueue;
MAX_CHUNKS_ALLOWED = (int)Math.Ceiling(1.5 * MAX_CHUNKS_IN_QUEUE);
Debug.Log(MAX_CHUNKS_IN_QUEUE + " " + MAX_CHUNKS_ALLOWED);
for (int i = 0; i < MAX_CHUNKS_IN_QUEUE; i++)
clearedChunks.Push(new VoxelChunk(0, Vector3.zero, 0, 0, 0, null));
clearedChunks.TrimExcess();
}
}
}