May*_*hak 1 c# linq csv linq-to-objects dictionary
我有一个字典,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" } }
};
Run Code Online (Sandbox Code Playgroud)
我需要输出为
string result = "some value, some Foo value, some Foobar value";
Run Code Online (Sandbox Code Playgroud)
请分享您的想法/解决方案,如何实现?
像这样:
String names = String.Join(", ", fooDic.Select(x => x.Value._barName));
Run Code Online (Sandbox Code Playgroud)
看一看: