Arrays
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?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nguyen LiemPosted Nov 23, 2005, 11:42 PM
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();
}
//////////////////////