How to print an array of strings using foreach loop in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[] { "c#", "c++", "java", "python" };

            foreach (string s in arr)
            {
                Console.WriteLine($"arr = {s}");
            }
        }
    }
}


/*
run:
      
arr = c#
arr = c++
arr = java
arr = python

*/

 



answered Dec 28, 2016 by avibootz
0 votes
using System;
 
namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = { "c#", "c", "c++", "java" };
 
            foreach (string s in arr)
                Console.WriteLine(s);
        }
    }
}
 
 
/*
run:
    
c#
c
c++
java
  
*/

 



answered Feb 10, 2017 by avibootz

Related questions

2 answers 249 views
1 answer 225 views
1 answer 185 views
1 answer 191 views
2 answers 283 views
1 answer 205 views
1 answer 172 views
...