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


C# Stack.Clone方法代码示例

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


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

示例1: TestCloneBasic

        public void TestCloneBasic()
        {
            Stack stk;
            Stack stkClone;

            A a1;
            A a2;

            //[]vanila 

            stk = new Stack();

            for (int i = 0; i < 100; i++)
                stk.Push(i);

            stkClone = (Stack)stk.Clone();

            Assert.Equal(100, stkClone.Count);

            for (int i = 0; i < 100; i++)
            {
                Assert.True(stkClone.Contains(i));
            }

            //[]making sure that this is shallow

            stk = new Stack();
            stk.Push(new A(10));
            stkClone = (Stack)stk.Clone();
            Assert.Equal(1, stkClone.Count);

            a1 = (A)stk.Pop();
            a1.I = 50;

            Assert.Equal(1, stkClone.Count);
            a2 = (A)stkClone.Pop();
            Assert.Equal(50, a2.I);

            //[]vanila with synchronized stack
            stk = new Stack();

            for (int i = 0; i < 100; i++)
                stk.Push(i);

            stkClone = (Stack)(Stack.Synchronized(stk)).Clone();
            Assert.Equal(100, stkClone.Count);
            Assert.True(stkClone.IsSynchronized);

            for (int i = 0; i < 100; i++)
            {
                Assert.True(stkClone.Contains(i));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:53,代码来源:Stack_Clone.cs

示例2: DefinedIn

        public mysSymbolSpace DefinedIn(
			Stack<mysSymbolSpace> spaceStack
		)
        {
            Stack<mysSymbolSpace> evaluationStack = spaceStack.Clone();

            while ( evaluationStack.Count > 0 ) {
                mysSymbolSpace space = evaluationStack.Pop();

                if ( space.Defined( this ) ) {
                    return space;
                }
            }

            return null;
        }
开发者ID:Koneke,项目名称:Yukkuri,代码行数:16,代码来源:mysSymbol.cs

示例3: EvaluateSymbol

        public static mysToken EvaluateSymbol(
			mysSymbol symbol,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            Stack<mysSymbolSpace> evaluationStack = spaceStack.Clone();

            while ( evaluationStack.Count > 0 ) {
                mysSymbolSpace space = evaluationStack.Pop();

                if ( space.Defined( symbol ) ) {
                    return space.GetValue( symbol );
                }
            }

            throw new ArgumentException( "Symbol isn't defined." );
        }
开发者ID:Koneke,项目名称:Yukkuri,代码行数:17,代码来源:mysSymbolSpace.cs

示例4: GetSymbol

        public static mysSymbol GetSymbol(
			string symbolString,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            Stack<mysSymbolSpace> evaluationStack = spaceStack.Clone();

            while ( evaluationStack.Count > 0 ) {
                mysSymbolSpace space = evaluationStack.Pop();

                mysSymbol symbol = space.Values.Keys
                    .FirstOrDefault( s => s.ToString() == symbolString );

                if ( symbol != null ) {
                    return symbol;
                }
            }

            // should this return null?
            return null;
        }
开发者ID:Koneke,项目名称:Yukkuri,代码行数:21,代码来源:mysSymbolSpace.cs

示例5: PerformActionOnAllStackWrappers

        public static void PerformActionOnAllStackWrappers(Stack stack, Action<Stack> action)
        {
            // Synchronized returns a slightly different version of Stack
            Stack[] stackTypes =
            {
                (Stack)stack.Clone(),
                Stack.Synchronized(stack)
            };

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

示例6: 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;
     Stack stk;		
     Stack stkClone;		
     A a1;
     A a2;
     try
     {
         strLoc = "Loc_384sdg";
         iCountTestcases++;
         stk = new Stack();
         for(int i=0; i<100; i++)
             stk.Push(i);
         stkClone = (Stack)stk.Clone();
         if(stkClone.Count!=100)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         for(int i=0; i<100; i++)
         {
             if(!stkClone.Contains(i))
             {
                 iCountErrors++;
                 Console.WriteLine( "Err_93475sdg! wrong value returned");
             }
         }
         strLoc = "Loc_384sdg";
         iCountTestcases++;
         stk = new Stack();
         stk.Push(new A(10));
         stkClone = (Stack)stk.Clone();
         if(stkClone.Count!=1)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         a1 = (A)stk.Pop();
         a1.I=50;
         if(stkClone.Count!=1)
         {
             iCountErrors++;
             Console.WriteLine( "Err_93745sdg! wrong value returned");
         }
         a2 = (A)stkClone.Pop();
         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,代码来源:co8619clone.cs


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