Learn How To Program In C# Part 20 – Foreach Loop

Hey, everybody. In this video, we’ll be going over a new
type of loop which is called a foreach loop. This for loop is pretty much designed to help
us work and deal with collections of data. An array is a collection, and we can loop
through it using foreach loop. You might have a question as to what the difference
is between a for loop and a foreach loop. And it’s a wonderful question, which is
why I brought back the old example from last time. int[] array=new int[5];
array[0]=1; array[1]=10;
array[2]=100; array[3]=1000;
array[4]=10000; for (int index=0; index

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


  • Leon Wol says:

    These videos has really helped me refresh my knowledge thanks!!

  • Eu Jeen says:

    Sir, is there anyway i can detect the row and column of the array? Because in that way, i can specifically choose which element to load to the Console.Writeline(). The video you showed outputs a default value of 0 for all elements. What if i want a list -1's as my default?

  • Thurman Merman says:

    Is it possible to display a size 10 string array in a column format using a foreach loop only , any suggestions ? Thank you

  • Thurman Merman says:

    I want to display the array in this format when it is compiled :

    Cherry Caramel Coffee Mint
    Strawberry Banana Apple Cookie n creme
    Chocolate Chocolate Chip

    any suggestions ? Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *