Arrays as Function Returns and Parameters

image_pdfimage_print
   
 
using System;

public class Starter {

    public static void Main() {
        int[] zArray = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
        string[] xArray = { "a", "b", "c", "d" };
        Console.WriteLine("List Numbers");
        MyClass.ListArray(zArray);
        Console.WriteLine("List Letters");
        MyClass.ListArray(xArray);
        Console.WriteLine("Total Numbers");
        MyClass.Total(zArray);
    }
}


public class MyClass {

    public static void ListArray(Array a) {
        foreach (object element in a) {
            Console.WriteLine(element);
        }
    }

    public static void Total(int[] iArray) {
        int total = 0;
        foreach (int number in iArray) {
            total += number;
        }
        Console.WriteLine(total);
    }
}