c# return array code example

Example 1: C# print array

string[] myArray = {"Dogs", "Cats", "Birds"};
foreach (string item in myArray)
{
  Console.WriteLine(item);
}

Example 2: C# array method reading and returning new array

static void Read(string fv, Person[] P, Money[] M, out int n)
        {
            int mon;
            string nm;
            int eu;
            int ct;
            using (StreamReader reader = new StreamReader(fv))
            {
                string line;
                line = reader.ReadLine();
                string[] parts;
                n = int.Parse(line);
                for (int i = 0; i < n; i++)
                {
                    line = reader.ReadLine();
                    parts = line.Split(';');
                    nm = parts[0];
                    eu = int.Parse(parts[1]);
                    ct = int.Parse(parts[2]);
                    mon = eu * 100 + ct;                
                    P[i] = new Person(nm, eu, ct);
                    M[i] = new Money(mon);
                }
            }
        }

Example 3: how to return array in function c#

static string[] GetNames()
        {
            return new [] { "Matthew", "Mark", "Luke", "John" };
            
        }