Array.Join in .Net?

后端 未结 7 805
挽巷
挽巷 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:03

    If you have an array of strings you can call String.join(String, String[]). You can use it even if you don't have an array of strings, you just have to be able to convert your objects to strings

    object[] objects = ...
    string[] strings = new string[objects.Length];
    for (int i = 0; i < objects.Length; i++)
      strings[i] = objects[i].ToString();
    string value = String.Join(", ", strings);
    

提交回复
热议问题