2013-06-24 1 views
0

이 질문은 지정된 조건을 충족시키기 위해 열거 형을 투영하는 데 기술 지원을 요청하는 것입니다.투영에 대한 Linq 설명

말,

공은 내가 공을 선택해야 다음 조건에 두 개의 빨간색 공 세 블루 balls.Based가 포함되어 있습니다.

(i) Each pair should contain one blue ball and one red ball 
(ii) if the ball is "Blue1" ignore it 

및 예상 결과가

{"Blue2","Red1" } 
{"Blue2","Red2" } 
{"Blue3","Red1" } 
{"Blue3","Red2" } 

입니다 그냥 그 결과를 다음 코드를 프로젝트에 완료 할 수 있습니다.

var bag = new[] { "Red1", "Red2", "Blue1", "Blue2", "Blue3" }; 
var BallsProjection = 
       from blueball in bag 
       from redball in bag 
       **(What is the condition required here to select the balls)** 
       select new { ball1 = blueball, ball2 = redball }; 

답변

0

다음 코드를 사용하여 원하는 결과를 얻을 수 있습니다.

var BallsProjection = 
       from blueball in bag 
       from redball in bag 
       where 
       blueball.Contains("Blue") && redball.Contains("Red") && blueball.CompareTo("Blue1") !=0 
      select new { ball1 = blueball, ball2 = redball }; 

요구 사항을 충족하기 위해이 코드를 향상시킬 수 있습니다.이 코드는 테스트하지 않았습니다.