2016-11-15 2 views
0

IEnumerable変数を作成して、別のリストの要素を特定のプロパティに渡すことは可能ですか?リストオブジェクトプロパティの列挙子

//... 
    SomeList<classA> MainList = new SomeList<classA>(); 
    IEnumerable<string> InnerList = ??MainList??; 
    MainList.add(new classA()); 
    Console.Writeline(InnerList.First()); 
// ->"Hello World" 
//... 

class classA{ 
    public string innerObject = "Hello World"; 
} 
+1

関連ドキュメントを:http://stackoverflow.com/documentation/c%23/68/linq-queries/303/select-transforming-elements –

答えて

1

あなたは、LINQを経由してそれを行うことができます。

var sampleList = new List<classA>(); 

var innerList = sampleList.Select(x => x.innerObject) //This creates an IEnumerable of all innerObjects in the original list 
関連する問題