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


C# Stack.Clone方法代码示例

本文整理汇总了C#中System.Collections.Stack.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Clone方法的具体用法?C# Stack.Clone怎么用?C# Stack.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.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:johnhhm,项目名称:corefx,代码行数:53,代码来源:Stack_Clone.cs

示例2: totalDue

        public double totalDue()
        /* pre:  Have list of delegates, possibly empty.
         * post: Calculate and return total amount outstanding for all delegates. Original list must retain original 
         *       ordering.
         */
        {

			double Total = 0;
			if (Delegates.Count == 0)
				return 0;

			reverseList ();
			Stack remover = new Stack ();
			while (Delegates.Count != 0) {
				Delegate add = (Delegate)Delegates.Pop();
				Total += add.getDue ();
				remover.Push (add);

			}
			Delegates = (Stack)remover.Clone();

			return Total;        
        }
开发者ID:BeesZA,项目名称:wrws202,代码行数:23,代码来源:Conference.cs

示例3: deleteDelegate

        // OPTIONAL TASKS 

        public bool deleteDelegate(int D)
        /* pre:  Have list of delegates, possibly empty.  Have identifier of delegate to remove
         * post: Remove the specified delegate from the list of delegates and return true.  If delegate is not in the list, 
         *       return false. If the removed delegate is also a presenter, display an appropriate warning message.
         *       NOTE: The list of delegates must retain the original ordering of the remaining delegates after processing 
         *       has been completed.
         */
        {
			int x = Delegates.Count;
			if (x == 0)
				return false;
			reverseList ();

			Stack remover = new Stack ();
			while (Delegates.Count != 0) {
				Delegate add = (Delegate)Delegates.Pop();
				if (add.DelID == D) {
					if (add.Presenter)
					Console.WriteLine ("Deleting a Presenter");
				} else {
					remover.Push (add);
				}
			}
			Delegates = (Stack)remover.Clone();
			if(remover.Count < x)
            return true;

			return false;


        }
开发者ID:BeesZA,项目名称:wrws202,代码行数:33,代码来源:Conference.cs

示例4: makePayment

        public void makePayment(int D, double Amnt)
        /* pre:  Have list of delegates, possibly empty. Have delegate identifier and amount paid.
         * post: Modify the relevant property for the given delegate.  Retain the original ordering of delegates in the list.
         */
        {

			if (Delegates.Count == 0)
				return;

			Stack remover = new Stack ();
			while (Delegates.Count != 0) {
				Delegate add = (Delegate)Delegates.Pop();
				if (add.DelID == D) {
					add.processPayment (Amnt);
				} 
					remover.Push (add);
			}

			Delegates = (Stack)remover.Clone();

            
        }
开发者ID:BeesZA,项目名称:wrws202,代码行数:22,代码来源:Conference.cs

示例5: CloneStack

		} // MatchOptionalArgumentList
	
	
	// Return a new Stack with the same entries as the given stack.
	// 
	// This is used when passing our "loops" or "withs" stack to
	// the code generator.  If we didn't make a clone, then the stack
	// passed to the code generator would be altered the next time we
	// push or pop an entry on our stack.
	// 
	// OPTIMIZATION snewman 8/29/01: it's pretty wasteful to clone the
	// stack on each use; we should implement a simple cache so as to only
	// make a new clone after the stack has been changed.
	private Stack CloneStack(Stack stack)
		{
		if (stack.Count == 0)
			return emptyStack;
		else
			return (Stack)(stack.Clone());
		
		} // CloneStack
开发者ID:emtees,项目名称:old-code,代码行数:21,代码来源:JParser2.cs

示例6: DumpStack

        private void DumpStack(Stack stack, string name)
        {
            Stack temp = (Stack)stack.Clone();

            string list = null;
            if( temp.Count == 0 )
            {
                list = "[Empty]";
            }
            else
            {
                while( temp.Count > 0 )
                {
                    object item = temp.Pop();
                    string text = null;
                    if( item is Array )
                    {
                        foreach( object obj in (Array)item )
                        {
                            if( text != null ) text += ", ";
                            text += "{" + obj.ToString() + "}";
                        }
                        text = "[" + text + "]";
                    }
                    else
                    {
                        text = "{" + item.ToString() + "}";
                    }
                    list = text + "  " + list;
                }
            }

            Debug.WriteLine(name + ": " + list);
        }
开发者ID:Marceli,项目名称:Roberta,代码行数:34,代码来源:OPathParser.cs


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