0

この質問は、指定された条件を満たすために列挙型を投影する際に技術的な助けを求めることです。

言う、

ボールには、2 つの赤いボールと 3 つの青いボールが含まれています。次の条件に基づいて、ボールを選択する必要があります。

(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 };
4

1 に答える 1

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 };

要件を満たすようにこのコードを拡張できます。このコードはテストしていません。

于 2013-06-24T10:40:58.730 に答える