-2

say I have an array with some strings in it

string[] array = {"item1", "item2"};

and now I want to use linq to on a single line take all the strings and put them into an array with a space between them I have tried

args.Select(x => x.ToString() + " ").ToString()

but this returns

Output Image

It is important to me that the code is on a single line of code, as it is not very clean in my standards or fitting to loop through with a foreach and add it to a string

ASh
  • 32,398
  • 9
  • 53
  • 74
Discord expert
  • 188
  • 1
  • 14

1 Answers1

3

Try String.Join(" ", array); it should do the trick

Bruno Belmondo
  • 2,219
  • 7
  • 18