Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将数组的值保存在一个字符串中_C#_Arrays_String - Fatal编程技术网

C# 将数组的值保存在一个字符串中

C# 将数组的值保存在一个字符串中,c#,arrays,string,C#,Arrays,String,我有一个包含4个值的数组: string[] selectedObject; 如何以字符串形式保存数组的所有4个值,如: string selectedObjects = ""; 我需要一个这样的字符串: selectedObjects = "123; 132; 231; 132;"; 如果您确实需要另一个,这将产生输出“123;132;231;132”最后,您可以手动添加此项以覆盖所有基础: if (!string.IsNullOrEmpty(selectedObjects))

我有一个包含4个值的数组:

string[] selectedObject;
如何以字符串形式保存数组的所有4个值,如:

string selectedObjects = "";
我需要一个这样的字符串:

selectedObjects = "123; 132; 231; 132;";
如果您确实需要另一个
,这将产生输出
“123;132;231;132”
最后,您可以手动添加此项以覆盖所有基础:

if (!string.IsNullOrEmpty(selectedObjects))
    selectedObjects = selectedObjects + ";";
这将为任何
selectedObject
数组长度(包括零)生成正确的输出

String selectedObjects = selectedObject.Aggregate((aggregation, currentString) => aggregation + "; " + currentString);
如果您确实需要另一个
,这将产生输出
“123;132;231;132”
最后,您可以手动添加此项以覆盖所有基础:

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

这将为任何
选择的对象
数组长度产生正确的输出,包括零。

那么
在最后?那
在最后?
String selectedObjects = selectedObject.Aggregate((aggregation, currentString) => aggregation + "; " + currentString);