stack示例_C.示例中的Stack.CopyTo()方法
stack示例
C#Stack.CopyTo()方法 (C# Stack.CopyTo() method)
Stack.CopyTo() method is used to copy the stack elements/objects to an existing array from the given index.
Stack.CopyTo()方法用于将堆栈元素/对象从给定索引复制到现有数组。
Syntax:
句法:
void Stack.CopyTo(Array, Int32);
Parameters: Array – Targeted array_name in which we have to copy the stack elements/objects, Int32 – is an index in targeted array_name from where stack elements/objects are copied.
参数: Array – 必须在其中复制堆栈元素/对象的目标array_name , Int32 –是目标array_name中从中复制堆栈元素/对象的索引。
Return value: void – it returns nothing.
返回值: void –不返回任何内容。
Example:
例:
declare and initialize a stack:
Stack stk = new Stack();
an array declaration for 20 elements:
int[] arr = new int[20];
insertting elements:
stk.Push(100);
stk.Push(200);
stk.Push(300);
stk.Push(400);
stk.Push(500);
using CopyTo(), copying stack elements to the array:
stk.CopyTo(arr, 3); //will copy from 3rd index in array
Output:
arr: 0 0 0 500 400 300 200 100 0 0 0 0 0 0 0 0 0 0 0 0
使用Stack.CopyTo()方法将堆栈元素/对象复制到数组的C#示例 (C# example to copy stack elements/objects to an array using Stack.CopyTo() 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();
//an array declaration for 20 elements
int[] arr = new int[20];
//insertting elements
stk.Push(100);
stk.Push(200);
stk.Push(300);
stk.Push(400);
stk.Push(500);
//printing stack elements
Console.WriteLine("Stack elements are...");
printStack(stk);
//printing array
Console.WriteLine("Array elements before CopyTo()...");
foreach (int item in arr)
{Console.Write(item + " ");
}
Console.WriteLine();
//using CopyTo(), copying stack elements to the array
stk.CopyTo(arr, 3);
//printing array
Console.WriteLine("Array elements after CopyTo()...");
foreach (int item in arr)
{Console.Write(item + " ");
}
Console.WriteLine();
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
Stack elements are...
500 400 300 200 100
Array elements before CopyTo()...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Array elements after CopyTo()...
0 0 0 500 400 300 200 100 0 0 0 0 0 0 0 0 0 0 0 0
Reference: Stack.CopyTo(Array, Int32) Method
参考: Stack.CopyTo(Array,Int32)方法
翻译自: https://www.includehelp.com/dot-net/stack-copyto-method-with-example-in-c-sharp.aspx
stack示例
stack示例_C.示例中的Stack.CopyTo()方法相关推荐
- java中的stack类和C++中的stack类的区别
文章目录 1 java中的stack类和C++中的stack类的区别 1.1 java中的stack类 1.2 C++中的stack类 1.3 分析 不经意间想到了这个问题,存到栈中的是对象的引用,还 ...
- c#中的long类型示例_C#中带示例的带符号字节数组
c#中的long类型示例 C#中的有符号字节数组 (Signed Byte Array in C#) In C#.Net, we can create a signed byte array by u ...
- c#中的long类型示例_C#中带示例的无符号字节数组
c#中的long类型示例 C#中的无符号字节数组 (Unsigned Byte Array in C#) In C#.Net, we can create an unsigned byte array ...
- stack示例_C.示例中的Stack.Clone()方法
stack示例 C#Stack.Clone()方法 (C# Stack.Clone() method) Stack.Clone() method is used to create a shallow ...
- c语言 函数的参数传递示例_C语言中带有示例的remove()函数
c语言 函数的参数传递示例 C语言中的remove()函数 (remove() function in C) The remove() function is defined in the <s ...
- json转string示例_C.示例中的String.Insert()方法
json转string示例 C#String.Insert()方法 (C# String.Insert() Method) String.Insert() method is used to inse ...
- json转string示例_C.示例中的String.Copy()方法
json转string示例 C#String.Copy()方法 (C# String.Copy() Method) String.Copy() method is used to copy a str ...
- c#equals方法源码_C#中的Int32.Equals()方法示例
c#equals方法源码 Int32.Equals()方法 (Int32.Equals() Method) This method is used to compare two integer obj ...
- C++中的stack类、QT中的QStack类
C++中的stack 实现一种先进后出的数据结构,是一个模板类. 头文件 #include<stack> 用法(以int型为例): stack <int> s; //定义一个i ...
最新文章
- 在EXCEL表格中怎么去掉全部的内容的最后一个字
- linux下curl的使用
- Linux Kernel TCP/IP Stack|Linux网络硬核系列
- 有效期判断功能 java_有效的Java第三版有哪些新功能?
- mac mysql 安装 简书_在Mac系统上配置MySQL以及Squel Pro
- 如何下载Discuz
- python实现卷积神经网络_【455】Python 徒手实现 卷积神经网络 CNN
- 资管运营BAND原创|那些年,资管运营业务交互中的酸甜苦辣
- 消息生产与消息存储——kafka源码探究之三
- java我的世界显示合成表_我的世界:若从你的背包移除“合成表”,回到5年前,最原始状态...
- MySQL数据操作与查询笔记 • 【第6章 聚合函数和分组查询】
- 无电流时二极管压降问题
- 工作日报这样写 大老板也挑不出错
- 中国Blog现状和发展初探
- 手提计算机10发现不到打印机,笔记本电脑连接打印机的详细步骤_笔记本电脑如何连接打印机-win7之家...
- CRM学习笔记类转换工具(pojo互转)上下文中获取用户名cookie工具
- (2020年最新版)App Store 审核指南
- 《SQL Server 2008从入门到精通》--20180724
- 少儿编程航天主题,scratch与航天航空主题:八大行星排排序
- STM32单片机开发实例 基于STM32单片机的智能血压计
热门文章
- python装饰器带参数函数二阶导数公式_一文搞定Python装饰器,看完面试不再慌
- python中代理模式分为几种_通俗 Python 设计模式——代理模式
- logisticregression参数_通俗地说逻辑回归【Logistic regression】算法(二)sklearn逻辑回归实战...
- css html 双面打印_从 Linux 命令行进行打印 | Linux 中国
- 4-数据结构-串的学习
- mysql修改表的字段_mysql修改表字段学习笔记
- 规培手册填写模板_9年老资料员经验分享,181套资料员模板+302页工作手册,成为优秀资料员还能提高工作效率,限时分享...
- python获取软件窗口句柄_Python获取浏览器窗口句柄过程解析
- LDAP命令介绍---dsconfig子命令----help-distribution显示与分发相关的子命令
- CentOS7下Hive的安装配置