개체 목록이 있습니다. 각 객체의 속성 하나 (문자열 값)를 문자열 목록으로 분리하는 데 관심이 있습니다. 이 필드 만 사용하여 문자열리스트를 만들 수 있습니까? 을 수동으로 사용하지 않고 루핑을 사용합니까?개체 목록에서 문자열 목록 생성
class MyObj
{
int ID {get;set;}
int AnotherID (get;set;}
string IneedThis {get;set;}
}
List<MyObj> sampleList = somehow_this_is_populated();
List<string> ls = how do I get this list with values equal to "sampleList.IneedThis"
'sampleList.Select (O => o.IneedThis) .ToList() ' –
왜 downvote? 그래서 OP는 LINQ를 알지 못했습니다. 잘 설명 된 질문입니다. LINQ 선택은 suff를 만드는 방법입니다. +1 – Paparazzi