PART I
C h a p t e r 1 9 :
L I N Q
561
PART IPART I
B Z
C X
C Y
C Z
The program begins by creating a class called
ChrPair
that will hold the results of the
query. It then creates two character arrays, called
chrs
and
chrs2
. It uses the following query
to produce all possible combinations of the two sequences:
var pairs = from ch1 in chrs
from ch2 in chrs2
select new ChrPair(ch1, ch2);
The nested
from
clauses cause both
chrs
and
chrs2
to be iterated over. Here is how it works.
First, a character is obtained from
chrs
and stored in
ch1
. Then, the
chrs2
array is enumerated.
With each iteration of the inner
from
, a character from
chrs2
is stored in
ch2
and the
select
clause is executed. The result of the
select
clause is a new object of type
ChrPair
that contains
the character pair
Do'stlaringiz bilan baham: |