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


C# Stack.FirstElement方法代码示例

本文整理汇总了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);
        }
开发者ID:NicolasBeuzart,项目名称:AnatomIL,代码行数:30,代码来源:StackTest.cs

示例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");
        }
开发者ID:NicolasBeuzart,项目名称:AnatomIL,代码行数:20,代码来源:StackTest.cs


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