字符串的快捷方式是什么?加入第二个示例中的非字符串数组?
string[] names = { "Joe", "Roger", "John" };
Console.WriteLine("the names are {0}", String.Join(", ", names)); //ok
decimal[] prices = { 39.99M, 29.99m, 29.99m, 19.99m, 49.99m };
Console.WriteLine("the prices are {0}", String.Join(", ", prices)); //bad overload
最佳答案
如果您有LINQ
:
decimal[] prices = { 39.99M, 29.99m, 29.99m, 19.99m, 49.99m };
Console.WriteLine("the prices are {0}",
String.Join(", ",
prices.Select(p => p.ToString()).ToArray()
)
);