Friday, April 19, 2024 16:01

Posts Tagged ‘foreach loop’

Yield break statement

Tuesday, May 11th, 2021

Whenever we use the yield keyword in a statement, we indicate that the method, operator, or get accessor in which it appears is an iterator. Of course, since we know that iterators are used to… duh! iterate on collections of data, and since we know that when iterating on a collection, we can use the break keyword to immediately terminate the iteration, it is only obvious that whenever we use an yield return statement to return values in an iterator, like I’ve shown in the previous lesson, we can also use yield break to terminate the iteration of the said iterator.… Read more

Yield return statement

Monday, February 22nd, 2021

In the previous lesson, I have talked about IEnumerable and IEnumerator, and how they help us when we need to iterate over collections of data. Let’s take an example that deals with those concepts:


C# IEnumerable

We have a function, GenerateRandomNumbers(), inside which we declare a List of ints, generate a number of random ints, equal to the _count parameter, add those random ints to the list, then return the list.… Read more

IEnumerator and IEnumerable

Friday, May 8th, 2020

Before we can start delving into LINQ, we need to first understand the underlying principles upon which it is built. LINQ is all about operations over collections, so, you’ve guessed it: we will be dealing with collections.

You already learned that of all data structures, arrays are the fastest, because they are unsorted non-generic data structures.… Read more

Foreach loop

Saturday, January 14th, 2017

The foreach loop is significantly more simpler than the For loop, but it’s also harder for the readers of this blog, since it’s based on concepts we haven’t learned yet. For this reason, i will simply tell you that a foreach loop was designed to iterate through all elements of an array, list or any other collection of elements that implement IEnumerable interface.… Read more


Follow the white rabbit