C# Language Using Range with various Linq methods


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

Select Example

Opposed to doing this:

var asciiCharacters = new List<char>();
for (var x = 0; x < 256; 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 even ones will be extracted

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