Most efficient way to append arrays in C#?

前端 未结 10 2139
挽巷
挽巷 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:26

    using this we can add two array with out any loop.

    I believe if you have 2 arrays of the same type that you want to combine into one of array, there's a very simple way to do that.

    Here's the code:

    String[] TextFils = Directory.GetFiles(basePath, "*.txt");
    String[] ExcelFils = Directory.GetFiles(basePath, "*.xls");
    String[] finalArray = TextFils.Concat(ExcelFils).ToArray();
    

    or

    String[] Fils = Directory.GetFiles(basePath, "*.txt");
    String[] ExcelFils = Directory.GetFiles(basePath, "*.xls");
    Fils = Fils.Concat(ExcelFils).ToArray();
    

提交回复
热议问题