博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stack.peek_C.示例中的Stack.Peek()方法
阅读量:2538 次
发布时间:2019-05-11

本文共 1965 字,大约阅读时间需要 6 分钟。

stack.peek

C#Stack.Peek()方法 (C# Stack.Peek() method)

Stack.Peek() method is used to get the object at the top from a stack. In we have discussed that it returns the object from the top and removes the object, but Stack.Peek() method returns an object at the top without removing it from the stack.

Stack.Peek()方法用于从堆栈顶部获取对象。 在我们讨论了它从顶部返回对象并删除该对象,但是Stack.Peek()方法在顶部将对象返回而不将其从堆栈中删除。

Syntax:

句法:

Object Stack.Peek();

Parameters: None

参数:

Return value: Object – it returns the top most object of the stack.

返回值: 对象 –它返回堆栈中最上面的对象。

Example:

例:

declare and initialize a stack:    Stack stk = new Stack();    insertting elements:    stk.Push(100);    stk.Push(200);    stk.Push(300);    stk.Push(400);    stk.Push(500);    printig stack's top object/element:    stk.Peek();        Output:    500

C#示例使用Stack.Peek()方法从堆栈顶部获取对象 (C# example to get an object at the top from the stack using Stack.Peek() method)

using System;using System.Text;using System.Collections;namespace Test{
class Program {
//function to print stack elements static void printStack(Stack s) {
foreach (Object obj in s) {
Console.Write(obj + " "); } Console.WriteLine(); } static void Main(string[] args) {
//declare and initialize a stack Stack stk = new Stack(); //insertting elements stk.Push(100); stk.Push(200); stk.Push(300); stk.Push(400); stk.Push(500); //printig stack's top object/element Console.WriteLine("object at the top is : " + stk.Peek()); //printing stack elements Console.WriteLine("Stack elements are..."); printStack(stk); //hit ENTER to exit Console.ReadLine(); } }}

Output

输出量

object at the top is : 500Stack elements are...500 400 300 200 100

Reference:

参考:

翻译自:

stack.peek

转载地址:http://ypvzd.baihongyu.com/

你可能感兴趣的文章
使用JustDecompile修改程序集
查看>>
SQLServer 分组查询相邻两条记录的时间差
查看>>
Swift语言指南(一)--语言基础之常量和变量
查看>>
关于webpack的使用
查看>>
Windows 2008 R2上配置IIS7或IIS7.5中的URLRewrite(URL重写)实例
查看>>
浅析java垃圾回收机制
查看>>
彻底理解线性筛选法
查看>>
Java Socket总结
查看>>
法语学习笔记
查看>>
使用css的类名交集复合选择器 《转》
查看>>
[USACO18DEC]The Cow Gathering
查看>>
情感分析-英文电影评论
查看>>
王者荣耀游戏服务器架构的演进读后感
查看>>
关于ajax请求controller返回中文乱码的解决方法!
查看>>
Objective-C 和 Core Foundation 对象相互转换的内存管理总结
查看>>
IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE...
查看>>
Linux nmon 命令
查看>>
使用 urllib 构造请求对象
查看>>
sql server book
查看>>
长亭技术专栏 安全攻防技术分享
查看>>