How to returns strings array reference from a method in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = string.Join(" ", GetArray());
            Console.WriteLine(s);
        }

        static string[] GetArray()
        {
            string[] arr = new string[3];

            arr[0] = "c#";
            arr[1] = "java";
            arr[2] = "c++";

            return arr;
        }
    }
}


/*
run:
      
c#
java
c++

*/

 



answered Dec 28, 2016 by avibootz
edited Dec 28, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = GetArray();

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

        static string[] GetArray()
        {
            string[] arr = new string[3];

            arr[0] = "c#";
            arr[1] = "java";
            arr[2] = "c++";

            return arr;
        }
    }
}


/*
run:
      
c#
java
c++

*/

 



answered Dec 28, 2016 by avibootz
...