2014-03-18 2 views
0

입력 날짜 시간 시작 및 끝이 목록의 요소 시간 범위에 속하는지 확인하기위한 시작 및 끝 시간 검색이 포함 된 개체 목록이 제공됩니다.열린 시간 슬롯에 대한 datetime의 목록 검색

즉. 8 : 30-9 : 30, 10 : 00-12 : 00,12 : 30-1 : 00,1 : 30-2 : 30,2 : 30-4 : 00

나는 다음과 함께 연주했습니다 : testPlans.Where (plan => plan.p_startDateTime> = startDate || 계획 .p_endDateTime < = endDate)

하지만 나는 혼란 스럽습니다.

+1

'|| '대신'&&'를 사용해 보셨습니까? – tinstaafl

답변

0

이것이 작동하는 것 같습니다. 개선은 언제나 환영합니다.

if(testPlans.Where(plan => startDate >= plan.p_startDateTime && endDate <= plan.p_endDateTime).Count() > 0) 
      { 
       return false; 
      } 
      else 
      { 
       if(testPlans.Where(plan => startDate > plan.p_startDateTime && startDate < plan.p_endDateTime).Count() > 0) 
       { 
        return false; 
       } 
       else 
       { 
        if(testPlans.Where(plan => endDate > plan.p_startDateTime && endDate < plan.p_endDateTime).Count() > 0) 
        { 
         return false; 
        } 
        else 
        { 
         return true; 
        } 
       } 
      } 
+0

'testPlans.Where (ef => ef.p_endDateTime> startDate) .All (fe => fe.p_startDateTime> endDate)'조금 짧습니다. – Ceilingfish

관련 문제