我有一个自定义对象列表,实际上这些是我存储在 IEnumerable 集合中的实体。我想将列表转换为逗号分隔的字符串,但我只想要一个特定的属性,How do I build a comma separated string with a specific property from a custom object list?
我知道我可以使用 "Foreach/For (int i .... "
构建一个逗号分隔的列表
但我认为有一种简单且更好的方法
那么简单的方法是什么?
这是我的 list
IEnumerable<BAL.Category> categories = chklCategories.CheckedItems.Cast<BAL.Category>();
//Category object has a property called Name , I want the list from that property
最佳答案
这很容易,不是吗?
string sCategories = string.Join(",", categories.Select(x => x.Name));
关于c# - 通过特定属性将列表转换为逗号分隔字符串的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20185084/