在 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