1

In Objective-C there is a method on NSArray which lets us join all elements by a string, so all the strings in the array will be joined by that string.

NSArray* arr = @[@"Hello", @"world"];
NSString* mystring = [arr componentsJoinedByString:@" "];

Any similar thing for something like a List in C#?

0

3 Answers 3

6

Yes, you can use string.Join

var mystring = string.Join(" ", myArray);
Sign up to request clarification or add additional context in comments.

Comments

2

Sure, but it's on the String class in C#:

var arr = new[] { "Hello", "world" };
var mystring = String.Join(" ", arr);

This works with different object types too (as String.Join has a Join<T>(string IEnumerable<T>) overload):

var arr = new[] { 4, 8, 15, 16, 23, 42 };
var mystring = String.Join(" ", arr);

Comments

0

Use String.Join

var joinedString = string.Join(" ", arr);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.