开发者

save values of array in one string

开发者 https://www.devze.com 2023-02-17 12:55 出处:网络
i have an array with 4 values: string[] selectedObject; how can i save all 4 values of 开发者_开发问答array in string like:

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;";


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.


String selectedObjects = selectedObject.Aggregate((aggregation, currentString) => aggregation + "; " + currentString);
0

精彩评论

暂无评论...
验证码 换一张
取 消