簡體   English   中英

在 C# 中將長長的 int[16] 列表​​轉換為 16 long int[] 的最快方法是什么?

[英]What's the fastest way to convert a long list of int[16] to 16 long int[] in C#

我有一個很長的(10000 多個條目)結構列表,每個結構都包含一個 int[16]。 我想轉置數據以創建 16 個 int[] 數組,這些數組的長度超過 10000 個條目。 本質上,我想轉置數據。 有沒有比遍歷列表並創建新條目更快的方法?

所以你只想要一個 int[16] 的數組?

也許 linq 可以做到這一點

var newArray = fooArray.Select(foo => foo.IntVal).ToArray();

你應該做這樣的事情:

struct Widget
{
  public int[] Values = new int[16]; 
}

public int[][] TransposeWidgets( List<Widget> widgets )
{
  int cols;
  int[][] result = new int[][];

  for ( int row = 0 ; i < 16 ; ++row )
  {
    results[row] = new int[ widgets.Count ];
    for ( int col = 0 ; col < widgets.Count ; ++col )
    {
      result[row][col] = widgets[col].Values[row];
    }
  }

}

盡管只迭代一次大列表可能會更快。 如果它真的很大,迭代該列表可能會導致分頁,這會減慢速度。

暫無
暫無

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

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