Most efficient way to append arrays in C#?

前端 未结 10 2090
挽巷
挽巷 2020-12-02 19:39

I am pulling data out of an old-school ActiveX in the form of arrays of doubles. I don\'t initially know the final number of samples I will actually retrieve.

What i

10条回答
  •  有刺的猬
    2020-12-02 20:19

    Concatenating arrays is simple using linq extensions which come standard with .Net 4

    Biggest thing to remember is that linq works with IEnumerable objects, so in order to get an array back as your result then you must use the .ToArray() method at the end

    Example of concatenating two byte arrays:

    byte[] firstArray = {2,45,79,33};
    byte[] secondArray = {55,4,7,81};
    byte[] result = firstArray.Concat(secondArray).ToArray();
    

提交回复
热议问题