本文整理汇总了C#中Stack.FirstElement方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.FirstElement方法的具体用法?C# Stack.FirstElement怎么用?C# Stack.FirstElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.FirstElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushAndPopItems
public void PushAndPopItems()
{
Stack s = new Stack();
StackItem si = new StackItem(typeof(Int32), 22);
StackItem si2 = new StackItem(typeof(String), "vrezvr");
s.Push(si.Type, si.Value);
s.Push(si2.Type, si2.Value);
Assert.That(s.Count == 2, "2 item has been push in stack but there is actually {0} item in stack",s.Count);
StackItem sip = s.Pop();
Assert.That(sip.Type, Is.EqualTo(typeof(string)), "Bad initialisation of the type or Pop method");
Assert.That(sip.Value, Is.EqualTo("vrezvr"), "Bad initialisation of the value or Pop method");
Assert.That(s.Count == 1, "2 item has been push in stack and one has been pop but there is actually {0} item in stack", s.Count);
sip = s.FirstElement();
Assert.That(sip.Type, Is.EqualTo(typeof(Int32)), "Bad initialisation of the type or CurrentStack method");
Assert.That(sip.Value, Is.EqualTo(22), "Bad initialisation of the value or CurrentStack method");
sip = s.Pop();
Assert.That(s.Count == 0, "The stack has to be empty but there is still {0} items in", s.Count);
}
示例2: FirstStackCreated
public void FirstStackCreated()
{
Stack s = new Stack();
Assert.That(s.Count == 0, "The stack is not empty : bad initialisation");
StackItem si = new StackItem(typeof(Int32), 22);
s.Push(si.Type, si.Value);
StackItem si2 = new StackItem(typeof(Int32), 54);
si2 = s.FirstElement();
Assert.That(s.Count != 0, "The stack is empty but si has been push on");
Assert.That(si2.Type, Is.EqualTo(typeof(Int32)), "Bad initialisation of the type");
Assert.That(si2.Value, Is.EqualTo(22), "Bad initialisation of the value");
}