简体   繁体   English

从Dictionary的值中获取名称,以逗号分隔的值字符串

[英]Get names from Dictionary's value as Comma separated value string

I Have a Dictionary Dictionary<int, Foo> fooDic as it's value is a class and Foo has a property _barName i Need all the names from fooDic as a CSV string... for example.. 我有一个字典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" } }
};

I need output as 我需要输出为

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

Please Share your ideas/solutions, How it can be achieved? 请分享您的想法/解决方案,如何实现?

Like this: 像这样:

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

Take a look: 看一看:

http://ideone.com/F4bLU http://ideone.com/F4bLU

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM