Looping Articles

The Internals of C# foreach

Many moons ago I discussed the foreach loop. Iexpand on that post here as I continue my series for the MSDN C#Developer Center. The advantage of a foreach loop over a forloop is the fact that it is unnecessary to know the number of itemswithin the collection when an iteration starts. This avoids iteratingoff the […]

Read more

Performance of Various Iteration Methods in .NET

Introduction I?ve been implementing numerical librariesin .NET and have come to some conclusions about iteration performance.My classes have to hold a large amount of data and be able to iteratethrough that data as quickly as possible. In order to compare variousmethods, I created a simple class called Data that encapsulates anarray of doubles. Method #1: […]

Read more

Visual Studio .Net Macros for Quick Insertion of C# Conditional and Iteration Statements

  To use, open Macro Explorer and copy and pasteinto an existing or new macro project. To run a macro place the cursorat the required insertion point in your document and double-click thename of the macro in Macro Explorer. You may wish to define moreconvenient keyboard shortcuts for each macro via the Tools | Customizemenu. […]

Read more

Building Your Own C# Enumerator To Use With The foreach Construct

We are going to use "foreach" to iterate through our collection of fruit objects. Lets assume that we have a class called Fruitwhich contains the fields; string name ,int num and bool ripe. We builda class called Fruits which represents a collection of fruit objects. public class Fruits{ //we don?t have to specify private as […]

Read more