Generate Sequence of Float Numbers within a Range using LINQ

Sometime back, I had written a post to Generate Odd Numbers within a Range using LINQ. Here’s a small modification to use LINQ to generate float numbers within a Range say - 20 to 40.


static void Main(string[] args)
var rng = Enumerable.Range(200, 200).Select(x => x / 10f);
foreach (float n in rng)

VB.NET (Converted Code)

Sub Main()
Dim rng = Enumerable.Range(200, 200).Select(Function(x) x / 10f)
For Each n As Single In rng
Next n
End Sub

As you know, the Enumerable.Range accepts two parameters: Start and Count. Since we are dividing the numbers in the range by 10F, the numbers gets generated in the following manner:

200/10 = 20 ; 201/10 = 20.1 ; 202/10 = 20.2

and so on..



Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: