Conversion from List to array T[]

后端 未结 7 916
一向
一向 2020-11-27 18:28

Is there a short way of converting a strongly typed List to an Array of the same type, e.g.: List to MyClass[]

相关标签:
7条回答
  • 2020-11-27 18:38

    Try using

    MyClass[] myArray = list.ToArray();
    
    0 讨论(0)
  • 2020-11-27 18:42

    One possible solution to avoid, which uses multiple CPU cores and expected to go faster, yet it performs about 5X slower:

    list.AsParallel().ToArray();
    
    0 讨论(0)
  • 2020-11-27 18:47
    List<int> list = new List<int>();
    int[] intList = list.ToArray();
    

    is it your solution?

    0 讨论(0)
  • 2020-11-27 18:47

    To go twice as fast by using multiple processor cores HPCsharp nuget package provides:

    list.ToArrayPar();
    
    0 讨论(0)
  • 2020-11-27 18:58

    Use ToArray() on List<T>.

    0 讨论(0)
  • 2020-11-27 19:00
    list.ToArray()
    

    Will do the tric. See here for details.

    0 讨论(0)
提交回复
热议问题