Tag Archives: loop

Compare performance looping over DateTime and integer variables in C#

The example Find Friday the Thirteenths in C# doesn’t really worry about performance. It uses integers to loop over the dates within a range. For every year between the start and end dates, the code considers the 13th of each … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment

Iterate over the items in arrays and lists in C#

You can use a foreach loop to iterate over the items in arrays, lists, collections, and other objects that have a GetEnumerator method. These loops are often more convenient than for or while loops because you don’t need to worry … Continue reading

Posted in arrays, lists, syntax | Tagged , , , , , , , , , , , , | Leave a comment

Loop over an array of unknown dimension in C#

The previous post Loop over entries in an array of unknown length in C# explains how to loop over the entries in a one- or two-dimensional array, but what do you do if you don’t know how many dimensions an … Continue reading

Posted in algorithms, arrays, recursion, variables | Tagged , , , , , , , , , , , , , , , , | 1 Comment

Loop over entries in an array of unknown length in C#

One way to loop through the items in an array is to hard code its length into the program. Alternatively you can use the array’s Length property to determine how many items it contains at runtime. Then if you later … Continue reading

Posted in arrays, variables | Tagged , , , , , , , , , , , , | Leave a comment

Compare loop performance in C#

The Code Project post FOREACH Vs. FOR (C#) examines the IL code created for a C# foreach loop and a for loop to compare loop performance. The author notices some unnecessary statements in the foreach loop and therefore concludes that … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , | Leave a comment