2013-01-21 1 views
2

나는 문자열의 배열을 가지고 :클래스/객체 목록에서 문자열을 일치 찾기

string[] PropertyIds= new string[5]; 

클래스 (Property)

List<Property> properties = new List<Property>(); 

클래스 Property가 다음 필드의 List : PropertyId (문자열) 및 PropertyDesc (문자열)

배열의 모든 PropertyId 값을 찾아야합니다. PropertyIds는 List 속성에 없습니다.

string[] PropertyIds= new string[] { "one", "two", "three" }; 
List<Property> properties = new List<Property>() 
{ 
    new Property("one","This is p1"), 
    new Property("Five","This is p5"), 
    new Property("six","This is p6"), 
}; 

그럼 내 결과는 해야한다.

답변

5

사용 Enumerable.Except는 두 시퀀스에서 차이를 얻을 수 있습니다 :

부동산 ID 클래스 속성에 정의 된 경우
var result = PropertyIds.Except(properties.Select(p => p.PropertyId)); 
+0

유형의 정수이다. 어떻게 두 시퀀스의 차이점을 얻을 수 있습니까? 감사합니다. –

+0

@palakmehta는 '선택 (p => p.PropertyId.ToString())'을 사용합니다. –