Skip to content

Arrays

Jon Morton

Asked Nov 23, 2005, 4:48 PM EST1 answer
Share
LinkedInX
Hello. I am trying to create an array with multiple types, like this: my_array = ["July", 346, "Bananas", 21.5, "Arrays"]; Is this possible? If not, how do you suggest i keep track of information with multiple types?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    You can get it here.
    my example.
    //////////////////////
       string[] arr = new string[]{"1", "2", "3"};

       ArrayList my_array = new ArrayList();

       my_array.Add(345);
       my_array.Add("Test");
       my_array.Add(arr);
       my_array.Add(23.4);
       Console.Write("arr : ");
       PrintValues(arr);
       Console.Write("\tmy_array 0 : " + my_array[0]);
       Console.Write("\tmy_array 1 : " + my_array[1]);
       Console.Write("\tmy_array 2 : " );
       PrintValues((string[])my_array[2]);
       Console.Write("\tmy_array 3 : " + my_array[3]);
    ///////////////////////////
    public static void PrintValues( Object[] myArr ) 
      {
       foreach ( Object i in myArr ) 
       {
        Console.Write( "\t{0}", i );
       }
       Console.WriteLine();
      }
    //////////////////////

    0