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


C# Queue.Clone方法代码示例

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


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

示例1: runTest

    public bool runTest()
    {
        //////////// Global Variables used for all tests

        String strValue = String.Empty;
        int iCountErrors = 0;
        int iCountTestcases = 0;

        Queue que;
        Queue queClone;

        Object dequeuedValue;

        A a1;
        A a2;

        try
        {
            /////////////////////////  START TESTS ////////////////////////////
            ///////////////////////////////////////////////////////////////////

            //[]vanilla 
            iCountTestcases++;

            que = new Queue();

            for (int i = 0; i < 100; i++)
                que.Enqueue(i);

            queClone = (Queue)que.Clone();
            if (queClone.Count != 100)
            {
                iCountErrors++;
                Console.WriteLine("Err_93745sdg! wrong value returned");
            }

            for (int i = 0; i < 100; i++)
            {
                if (!queClone.Contains(i))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_93475sdg! wrong value returned");
                }
            }

            //[]making sure that this is shallow
            iCountTestcases++;

            que = new Queue();

            que.Enqueue(new A(10));

            queClone = (Queue)que.Clone();
            if (queClone.Count != 1)
            {
                iCountErrors++;
                Console.WriteLine("Err_93745sdg! wrong value returned");
            }

            a1 = (A)que.Dequeue();
            a1.I = 50;

            if (queClone.Count != 1)
            {
                iCountErrors++;
                Console.WriteLine("Err_93745sdg! wrong value returned");
            }

            a2 = (A)queClone.Dequeue();

            if (a2.I != 50)
            {
                iCountErrors++;
                Console.WriteLine("Err_93745sdg! wrong value returned, " + a2.I);
            }

            //[]Empty Que
            iCountTestcases++;

            que = new Queue();
            queClone = (Queue)que.Clone();

            if (queClone.Count != 0)
            {
                iCountErrors++;
                Console.WriteLine("Err_4488ajied! Count wrong value returned Expected={0} Actual={1}", 0, queClone.Count);
            }

            queClone.Enqueue(100);

            if ((int)(dequeuedValue = queClone.Dequeue()) != 100)
            {
                iCountErrors++;
                Console.WriteLine("Err_45884ajeiod! wrong value returned Expected={0} Actual={1}", 100, dequeuedValue);
            }

            //[]After Clear
            iCountTestcases++;

            que = new Queue();
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:Queue_Clone.cs

示例2: PerformActionOnAllQueueWrappers

        public static void PerformActionOnAllQueueWrappers(Queue queue, Action<Queue> action)
        {
            // Synchronized returns a slightly different version of Queue
            Queue[] queueTypes =
            {
                (Queue)queue.Clone(),
                Queue.Synchronized(queue)
            };

            foreach (Queue queueType in queueTypes)
            {
                action(queueType);
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:14,代码来源:Helpers.cs

示例3: 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;		
     Queue queClone;		
     A a1;
     A a2;
     try
     {
         strLoc = "Loc_384sdg";
         iCountTestcases++;
         que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i);
         queClone = (Queue)que.Clone();
         if(queClone.Count!=100)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         for(int i=0; i<100; i++)
         {
             if(!queClone.Contains(i))
             {
                 iCountErrors++;
                 Console.WriteLine( "Err_93475sdg! wrong value returned");
             }
         }
         strLoc = "Loc_384sdg";
         iCountTestcases++;
         que = new Queue();
         que.Enqueue(new A(10));
         queClone = (Queue)que.Clone();
         if(queClone.Count!=1)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         a1 = (A)que.Dequeue();
         a1.I=50;
         if(queClone.Count!=1)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         a2 = (A)queClone.Dequeue();
         if(a2.I!=50)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned, " + a2.I);
         }
     } 
     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:ArildF,项目名称:masters,代码行数:72,代码来源:co8615clone.cs


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