string[] source = new string[]{"one", "two", "three"}; string result = string.Join(",", source);
但是當陣列中還有陣列(jagged array, e.g. array of array)的時候怎麼辦呢?
這時候LINQ的Select語法就派上用場了,一層一層的串上去就對了
string[][][] source = new string[][][]{ new string[][]{ new string[]{"1", "2", "3"}, new string[]{"one", "two", "three"} }, new string[][]{ new string[]{"4", "5", "6"}, new string[]{"five", "six", "seven"} } }; string result = string.Join(",", source.Select(m => string.Join(",", m.Select(n => string.Join(",", n)))));
如此一來就可以成功串接每一層陣列中的字串了。
Reference:
https://stackoverflow.com/questions/35102320/c-sharp-copying-jagged-arrays-to-strings
沒有留言:
張貼留言