Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#2
Well done!

I'm currently researching more into C# and noticed there is one more loop style - the For-Each loop. Found in the System.Collections namespace, it is used to iterate through items in a list (array). This is a great implementation which allows easy processing or listing like attributes in said array.

Counter and algorithms can be set in place if certain elements need to be ignored! One can also break from the loop at any time.

Off the MSDN:

Code:
    class ForEachTest
    {
        static void Main(string[] args)
        {
            int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 };
            foreach (int i in fibarray)
            {
                System.Console.WriteLine(i);
            }
        }
    }
    /*
    Output:
    0
    1
    1
    2
    3
    5
    8
    13
    */

Messages In This Thread
-C#- Loops - by MindHACKer - Nov 29 2011, 01:10 PM
RE: -C#- Loops - by Helices - Nov 29 2011, 06:07 PM
RE: -C#- Loops - by MindHACKer - Nov 29 2011, 06:10 PM
RE: -C#- Loops - by Leaky - Nov 30 2011, 05:17 PM
RE: -C#- Loops - by MindHACKer - Nov 30 2011, 05:26 PM

Users browsing this thread: 1 Guest(s)