在 C# 中将整个 LinkedList 复制到 Array 中
复制整个 LinkedList 到 Array 时,代码如下 −
示例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
int[] strArr = new int[5];
list.CopyTo(strArr, 0);
foreach(int str in strArr){
Console.WriteLine(str);
}
}
}输出
将产生以下输出 −
100 200 300 0 0
示例
现在让我们看另一个示例 −
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
int[] strArr = new int[10];
list.CopyTo(strArr, 4);
foreach(int str in strArr){
Console.WriteLine(str);
}
}
}输出
将产生以下输出 −
0 0 0 0 100 200 300 0 0 0
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP