1

i have an array with 4 values:

string[] selectedObject;

how can i save all 4 values of array in string like:

string selectedObjects = "";

i need one string like this:

selectedObjects = "123; 132; 231; 132;";

2 Answers 2

8
string selectedObjects = string.Join("; ", selectedObject);

This will produce the output "123; 132; 231; 132" - If you really wanted another ; at the end you could add this manually to have all bases covered:

if (!string.IsNullOrEmpty(selectedObjects))
    selectedObjects = selectedObjects + ";";

This will produce the right output for any selectedObject array length, including zero.

Sign up to request clarification or add additional context in comments.

1 Comment

What about the ; at the end?
-1
String selectedObjects = selectedObject.Aggregate((aggregation, currentString) => aggregation + "; " + currentString);

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.