我希望能够在两个不同的数组中存储一首歌和相应的艺术家,然后将它们组合在一起,用逗号分隔。
string[] songs = new string[3];
songs[0] = "Song One";
songs[1] = "Song Two";
songs[2] = "Song Three";
string[] artists = new string[3];
artists[0] = "Artist for Song One";
artists[1] = "Artist for Song Two";
artists[2] = "Artist for Song Three";
我如何Response.Write
如下格式:
歌曲信息:歌曲一,艺术家一
歌曲信息:歌曲二,艺术家二
歌曲信息:歌曲三,艺术家三
我可以使用这样的东西吗? :
string[] PrintToPage = songs.Concat(artist).ToArray();
我不明白我怎么能做到这一点?
(同意,我只能使用一个数组,但我想学习)。
最佳答案
您可以使用 Zip在同一索引处合并数组成员的扩展方法:
var output = string.Join(" ", songs.Zip(artists, (s, a) => $"Song Info: {s}, {a}"));
关于c# - 如何将两个数组打印到一个页面,用逗号分隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41074494/