UFO ET IT

배열을 문자열로 변환

ufoet 2020. 11. 9. 21:41
반응형

배열을 문자열로 변환


이 출력을 문자열로 만드는 방법은 무엇입니까?

List<string> Client = new List<string>();
foreach (string listitem in lbClients.SelectedItems)
{
    Client.Add(listitem);
}

다음을 사용하여 어레이를 결합 할 수 있습니다.

string.Join(",", Client);

그러면 원하는대로 출력 할 수 있습니다. 쉼표를 원하는대로 공백, 파이프 등으로 변경할 수 있습니다.


아마도 String.Join의 과부하와 같은 것을 원할 것입니다.

String.Join<T> Method (String, IEnumerable<T>)

문서 :

http://msdn.microsoft.com/en-us/library/dd992421.aspx

귀하의 예에서는

String.Join("", Client);


나의 제안:

using System.Linq;

string myStringOutput = String.Join(",", myArray.Select(p => p.ToString()).ToArray());

참조 : https://coderwall.com/p/oea7uq/convert-simple-int-array-to-string-c

참고 URL : https://stackoverflow.com/questions/13426463/convert-an-array-to-string

반응형