From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The Range method

The Range method

- The last generator we'll look at is called Range. Lets see what it says in the Help, generates a sequence of integral numbers within a specified range. easy to use. Here I'm setting the start value to 1000 and I want 30 items. When I dump this, I start at 1000 and end at 1029. That's works, It's simple to use. If you want to do something like, you want to skip numbers, then you're going to need some extra code and that's why I've got this second demo, common at that line and uncommon at this line here. What I've done here is I generate the range, same as before but now I do a Where clause after I've generated the range and then I say, mod two equal equal to one. So this will only return the odd numbers. So I'm feeding the results from enumerable range which is generating a enumerable of this case integers, feeding that to Where, and it's filtering that down to a subset like this. Not like that. Let's try it again.…

Contents