我与一个函数执行操作(我想用LINQ),并返回这样的对象的集合库工作:
System.Collections.Generic.IEnumerable<ColorInformation>
Run Code Online (Sandbox Code Playgroud)
这个"ColorInformation"是一个看起来像这样的类:
public class ColorInformation
{
private readonly System.Drawing.Color color;
private readonly string rowTitle;
private readonly System.Collections.Generic.List<int> ids;
public ColorInformation(System.Drawing.Color color, string rowTitle,
System.Collections.Generic.List<int> ids)
{
this.color = color;
this.rowTitle = rowTitle;
this.ids = ids;
}
public string RowTitle
{
get { return rowTitle; }
}
public System.Drawing.Color Color
{
get { return color; }
}
public System.Collections.Generic.List<int> Ids
{
get { return ids; }
}
}
Run Code Online (Sandbox Code Playgroud)
我有兴趣检索返回的集合中所有对象的所有ID.我试过这个:
var myids = from ids in theCollectionReturned select ids.Ids;
Run Code Online (Sandbox Code Playgroud)
这给了我一个带有ID的列表集合.我真正想要的只是一个包含所有整数ID的列表.所以,必须在某处进行演员或某种转换,我不知道该怎么做.任何帮助,提示,阅读,代码,示例将不胜感激.谢谢!
我真正想要的只是一个包含所有整数ID的列表.
这听起来像你想要的:
var ids = theCollectionReturned.SelectMany(info => info.Ids);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |