簡體   English   中英

C# 將元組的 LinkedList 轉換為元組的數組

[英]C# Convert LinkedList of tuples to Array of tuples

我有以下鏈接列表:

private LinkedList<Tuple<string, string>> textList = 
  new LinkedList<Tuple<string, string>> ();

鏈表由未知數量的元素組成。

我想將此鏈表轉換為元組數組 我嘗試使用CopyTo()方法:

Tuple<string, string>[] array;
textList.CopyTo(array, 0);

但這似乎不起作用,在這里我收到運行時錯誤:

使用未簽名的局部變量“數組”

我是使用正確的方法還是有其他方法可以做到?

您可以嘗試使用Linq ( .ToArray() ) 並讓 .net 為您創建數組:

using System.Linq;

...

private LinkedList<Tuple<string, string>> textList = 
  new LinkedList<Tuple<string, string>>();

...

Tuple<string, string>[] array = textList.ToArray();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM