Enumerable.Range by example

C# Enumerable.Range function generates sequence of numbers. This article explores details of the Range function as well as its use cases. Enumerable.Range overview It takes two arguments. First argument is the first number in sequence (e.g. 10, means that the first number in sequence is 10). Second argument is the number of items in sequence (e.g. 11 means that it will return 11 numbers). It returns IEnumerable<int> which contains generated sequence. Keep in mind that each subsequent number is incremented by 1, which also means that it’s in ascending order. This however can be changed with some Linq tricks (check examples below). ...

October 31, 2019 · 4 min · Zbigniew

Where() Select()

This post is quick intro for beginners. I’ll introduce you to 2 Linq methods Select and Where. We use those functions to manipulate data set. All 2 can be applied to all types implementing IEnumerable interface. It means that you can apply them to data retrieved from database (IQueryable), list (List/IList implements IEnumerable), arrays (which also implements IEnumerable) and others. It’s important to know that each one of those functions return new IEnumerable. Even if we execute these methods on array (e.g. int[]) it returns enumerable (e.g. IEnumerable<int>). Note that it works a bit different for IQueryable and database operations. Since this is an introductory level post I’ll show you how to use them using array based examples. ...

July 28, 2019 · 2 min · Zbigniew