SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 136 | Next

Scott Klein

"Professional LINQ"


Range
The Range operator creates a collection that contains a sequence of numbers. It takes two parameters.
The first is the integer value at which to start the sequence, and the second is the number of sequential
integers to generate.
Here??™s an example in which the Range operator is used to generate a sequence of numbers starting at 1
and stopping at 10:
var coolmath = Enumerable.Range(1, 10);
for each (int num in coolmath)
listbox1.Items.Add(num);
The results are
1
2
3
4
6
7
8
9
10
72
Chapter 4: LINQ Standard Query Operators
Other operators can be added to this as well. The following example generates a list of numbers from 1
to 10 but also uses the Reverse operator to generate them backward.
var coolmath = Enumerable.Range(1, 10).Reverse();
for each (int num in coolmath)
listbox1.Items.Add(num);
The results are
10
9
8
7
6
5
4
3
2
1
In the next example, the Range operator is used to create a sequence of numbers from 1 to 5 and then
multiply each number by 5:
var coolmath = Enumerable.Range(1, 5).Select(x => x * 5);
for each (int num in coolmath)
listbox1.


Pages:
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6