21

I have an array of object e.g:

MyObject[] objs;

and within MyObject it contains a string property,

object[0].stringValue

If I want to join the whole array of objects by their stringValue, how can I do it?

1
  • 1
    Which version of .NET are you using? Commented Mar 17, 2011 at 22:46

2 Answers 2

43
string.Join(",",objs.Select(w=>w.stringValue))
Sign up to request clarification or add additional context in comments.

2 Comments

Fiora, is that you?!?!
Note that pre-.Net 4.0, you need to convert it to an array like so: string.Join(",",objs.Select(w=>w.stringValue).ToArray()).
5

Do you mean to use string.Join to concatenate a property from multiple MyObject objects into one single string?

Then:

string str = string.Join(",", objs.Select(x => x.SomeProperty));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.