2016-11-15 6 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

Связанные Docs: 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 
Смежные вопросы