我有一个自定义对象列表,实际上这些是我存储在IEnumerable集合中的实体.我想将列表转换为逗号分隔的字符串,但我只想要一个特定的属性,如何使用自定义对象列表中的特定属性构建逗号分隔的字符串?
我知道我可以通过使用a来构建逗号分隔列表,"Foreach / For (int i .... "
但我认为有一个简单而且更好的方法,那么这将是多么简单的方法?
这是我的清单
IEnumerable<BAL.Category> categories = chklCategories.CheckedItems.Cast<BAL.Category>();
//Category object has a property called Name , I want the list from that property
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我已经解释了我想要的内容,请有人帮我解决这个问题.
public class Person
{
public IEnumerable<Child> Children { get; set; }
}
public class Child
{
public IEnumerable<GrandChild> GrandChildren { get; set; }
}
public class SearchingClass
{
public void Search()
{
IEnumerable<Person> persons = MyPersons;
IEnumerable<GrandChild> grandChildren = MyGrandChildren
//Now I want only the Grand Children who are grand children of persons in Persons List
//How can I write a query for this ?
}
}
Run Code Online (Sandbox Code Playgroud)