本文整理汇总了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));
}
}
示例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;
}
示例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." );
}
示例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;
}
示例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);
}
}
示例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;
}
}