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 388 views
1 answer 293 views
1 answer 331 views
1 answer 300 views
1 answer 306 views
2 answers 399 views
1 answer 274 views
...