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


C# Queue.TrimToSize方法代码示例

本文整理汇总了C#中Queue.TrimToSize方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.TrimToSize方法的具体用法?C# Queue.TrimToSize怎么用?C# Queue.TrimToSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.TrimToSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TrimToSizeTest

		public void TrimToSizeTest()
		{
			var queue = new Queue(64);

			Assert.AreEqual(0, queue.Count);
			Assert.AreEqual(64, queue.Capacity);

			queue.Enqueue("No.1");
			queue.Enqueue("No.2");

			Assert.AreEqual(2, queue.Count);
			Assert.AreEqual(64, queue.Capacity);

			queue.TrimToSize();

			Assert.AreEqual(2, queue.Count);
			Assert.AreEqual(2, queue.Capacity);
		}
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:18,代码来源:QueueTests.cs

示例2: TrimToSize_Wrapped

        public static void TrimToSize_Wrapped()
        {
            var queue = new Queue(100);

            // Insert 50 items in the Queue
            for (int i = 0; i < 50; i++)
            {
                queue.Enqueue(i);
            }

            // Insert and Remove 75 items in the Queue. This should wrap the queue 
            // where there is 25 at the end of the array and 25 at the beginning
            for (int i = 0; i < 75; i++)
            {
                queue.Enqueue(i + 50);
                queue.Dequeue();
            }

            queue.TrimToSize();
            Assert.Equal(50, queue.Count);
            Assert.Equal(75, queue.Dequeue());

            queue.Enqueue(100);
            Assert.Equal(50, queue.Count);
            Assert.Equal(76, queue.Dequeue());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:QueueTests.cs

示例3: runTest

    public bool runTest()
    {
        //////////// Global Variables used for all tests
        String strValue = String.Empty;
        int iCountErrors = 0;
        int iCountTestcases = 0;

        Queue que;
        Object dequeuedValue;

        try
        {
            /////////////////////////  START TESTS ////////////////////////////
            iCountTestcases++;
            que = new Queue();

            try
            {
                que.TrimToSize();
            }
            catch (Exception)
            {
                iCountErrors++;
            }

            que = new Queue();
            for (int i = 0; i < 1000; i++)
            {
                que.Enqueue(i);
            }

            try
            {
                que.TrimToSize();
            }
            catch (Exception)
            {
                iCountErrors++;
            }

            que = new Queue(100000);

            try
            {
                que.TrimToSize();
            }
            catch (Exception)
            {
                iCountErrors++;
            }

            //[]Empty Queue
            iCountTestcases++;

            que = new Queue();
            que.TrimToSize();

            if (que.Count != 0)
            {
                iCountErrors++;
            }

            que.Enqueue(100);

            if ((int)(dequeuedValue = que.Dequeue()) != 100)
            {
                iCountErrors++;
            }

            //[]After Clear
            iCountTestcases++;

            que = new Queue();

            //    Insert 50 items in the Queue
            for (int i = 0; i < 100; i++)
            {
                que.Enqueue(i);
            }

            que.Clear();
            que.TrimToSize();

            if (que.Count != 0)
            {
                iCountErrors++;
            }

            que.Enqueue(100);
            if ((int)(dequeuedValue = que.Dequeue()) != 100)
            {
                iCountErrors++;
            }

            //[]After Dequeue all items
            iCountTestcases++;

            que = new Queue();

            //    Insert 50 items in the Queue
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:corefx,代码行数:101,代码来源:Queue_TrimToSize.cs

示例4: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Queue que;		
     try
     {
         strLoc = "Loc_384sdg";
         iCountTestcases++;
         que = new Queue();
         try
         {
             que.TrimToSize();
         }
         catch(Exception ex)
         {
             iCountErrors++;
             Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
         }
         que = new Queue();
         for(int i=0; i<1000; i++)
         {
             que.Enqueue(i);
         }
         try
         {
             que.TrimToSize();
         }
         catch(Exception ex)
         {
             iCountErrors++;
             Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
         }
         que = new Queue(100000);
         try
         {
             que.TrimToSize();
         }
         catch(Exception ex)
         {
             iCountErrors++;
             Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
         return true;
     }
     else
     {
         Console.WriteLine("FAiL! "+s_strTFName+" ,inCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:63,代码来源:co8823trimtosize.cs


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