当前位置: 首页>>代码示例>>C#>>正文


C# Stack.TrimExcess方法代码示例

本文整理汇总了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();
        }
开发者ID:AndrewNeo,项目名称:muftec,代码行数:11,代码来源:StackOperations.cs

示例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);
        }
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:47,代码来源:Program.cs

示例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);
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:15,代码来源:StackTests.cs

示例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);
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:13,代码来源:StackTests.cs

示例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();
                }
            }
        }
开发者ID:boniboni,项目名称:Ferram-Aerospace-Research,代码行数:29,代码来源:VehicleVoxel.cs


注:本文中的Stack.TrimExcess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。