0

私は IList を持っています--->

IList<Test> list;   

リストには、以下に示すクラス Test のオブジェクトが含まれています。

list.Add(new Test{ id = 1, name = "abc" })
list.Add(new Test{ id = 2, name = "xyz" })
list.Add(new Test{ id = 3, name = "nmo" })

クラス Test は --->

Class Test
{
    int id;
    string name;
}

ここで、(リストのすべての要素の)すべての名前フィールドを選択したい--->

IList<string> nameList = ???  

私はこれで立ち往生しました(LINQ c#に関する知識の欠如)

4

2 に答える 2

3

LINQ を使用できますSelect

 nameList = list.Select(x => x.name).ToList();
于 2013-05-03T07:38:15.227 に答える
2
IList<string> nameList = YourCollection.Select(item=> item.name).ToList();
于 2013-05-03T07:38:44.063 に答える