1

我有一个字典Dictionary<int, Foo> fooDic,因为它的值是一个类并且Foo有一个属性_barName我需要所有名称fooDic作为 CSV 字符串...例如..

var fooDic = new Dictionary<int, Foo>()
{
    { 0, new Foo { _barId = 10, _barName = "some value" } },
    { 1, new Foo { _barId = 15, _barName = "some Foo value" } }, 
    { 2, new Foo { _barId = 25, _barName = "some Foobar value" } }
};

我需要输出为

string result = "some value, some Foo value, some Foobar value";

请分享您的想法/解决方案,如何实现?

4

1 回答 1

9

像这样:

String names = String.Join(", ", fooDic.Select(x => x.Value._barName));

看一看:

http://ideone.com/F4bLU

于 2012-07-27T09:31:54.030 回答