[英]How to print array in format [1, 2, 3, 4 ,5] with string.Join in C#?
i have an array 1 2 3 4 5
in C#.我在 C# 中有一个数组
1 2 3 4 5
。 I just want to print in format with: [] ;我只想用以下格式打印: [] ; Ex.
前任。
[1, 2, 3, 4, 5]
You can use string.Format
and string.Join
combined您可以将
string.Format
和string.Join
结合使用
var output = string.Format("[{0}]", string.Join(",", yourArray));
and then you just need to print output
string anywhere you want.然后你只需要在你想要的任何地方打印
output
字符串。
String.Format
will provide you with possibility to wrap joined string with [
and ]
without concatenating string manually. String.Format
将为您提供用[
和]
包装连接字符串的可能性,而无需手动连接字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.