Array.Join in .Net?

后端 未结 7 814
挽巷
挽巷 2020-12-10 10:26

Ok, this is a dumb thing that I\'m sure I\'ve done dozens of times but for some reason I can\'t find it.

I have an array... And want to get a string with the content

7条回答
  •  孤城傲影
    2020-12-10 11:21

    you don't need to convert the array into a string array in .NET Framework 4. i don't know about previous Frameworks. so the previous code spends several lines converting your int array into a string array. just skip that step (if it also works in your Framework).

    string[] sA = "11,12,13".Split(',');
    int[] iA = { 21, 22, 23};
    Console.WriteLine(string.Join("+", iA) + " -- " + string.Join("+", sA));
    
    /* displays:
    21+22+23 -- 11+12+13
    */
    

提交回复
热议问题