Using Range with various Linq methods

suggest change

You can use the Enumerable class alongside Linq queries to convert for loops into Linq one liners.

Select Example

Instead of doing this:

var asciiCharacters = new List<char>();
for (var x = 0; x < 256; x++)
{
    asciiCharacters.Add((char)x);
}

You can do this:

var asciiCharacters = Enumerable.Range(0, 256).Select(a => (char) a);

Where Example

In this example, 100 numbers will be generated and the even ones will be extracted.

var evenNumbers = Enumerable.Range(1, 100).Where(a => a % 2 == 0);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents