Home EducationSubjectsIT Studies Subscribe to RSS

What Would Be The Output For This In C# Language?

What would be the output? Could you explain to me why foreach loop is used here? It says that it will print all elements in an array? This code is displaying zeroes as output. Foreach (int Y In Arr) Console.WriteLine(y);

Answer Question

1 Answer - Sort by: Date | Rating


    using System;
    using System.Collections.Generic
    using System.Text
    class ForEachTest
    {
    &nbsp static void Main(string[] args)
    &nbsp {
    &nbsp &nbsp int[] Arr = new int[] { 0, 1, 2, 3, 5, 8, 13 };
    &nbsp &nbsp foreach (int Y in Arr)
    &nbsp &nbsp {
    &nbsp &nbsp &nbsp System.Console.WriteLine(Y);
    &nbsp &nbsp }
    &nbsp }
    }

    // This code will print out the contents of ARR
    1 0

    Jnawrocki 

    answered 1 year ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International