1

関数で操作を実行し(LINQを使用していると思います)、次のようなオブジェクトのコレクションを返すライブラリを使用しています。

System.Collections.Generic.IEnumerable<ColorInformation>

この「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; }
    }
}

返されたコレクション内のすべてのオブジェクトのすべての ID を取得することに興味があります。私はこれを試しました:

var myids = from ids in theCollectionReturned select ids.Ids;

これにより、ID を持つリストのコレクションが得られます。私が実際に欲しいのは、すべての整数 ID を含む 1 つのリストだけです。そのため、どこかにキャストまたは何らかの変換が必要であり、その方法がわかりません。ヘルプ、ヒント、読み物、コード、例をいただければ幸いです。ありがとう!

4

1 に答える 1

8

私が実際に欲しいのは、すべての整数 ID を含む 1 つのリストだけです。

あなたが望むように聞こえます:

var ids = theCollectionReturned.SelectMany(info => info.Ids);
于 2012-10-31T16:02:46.650 に答える