リストがあります:
List<int> list = new List<int> {1, 2, 3, 4, 5};
リストの文字列表示を取得したい場合。しかし、コードlist.ToString()
リターン"System.Collections.Generic.List'1[System.Int32]"
私はこのような標準的な方法を探しています:
string str = list.Aggregate("[",
(aggregate, value) =>
aggregate.Length == 1 ?
aggregate + value : aggregate + ", " + value,
aggregate => aggregate + "]");
そして得る"[1, 2, 3, 4, 5]"
ICollection を適切な文字列形式で表示するための標準的な .NET メソッドはありますか?