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

2 Answers

0 votes
using System;
using System.Linq;

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

            foreach (string s in arr.Reverse())
            {
                Console.WriteLine(s);
            }
        }
    }
}


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

 



answered Feb 10, 2017 by avibootz
0 votes
using System;
using System.Linq;

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

            foreach (string s in arr.Reverse<string>())
            {
                Console.WriteLine(s);
            }
        }
    }
}


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

 



answered Feb 10, 2017 by avibootz

Related questions

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