Dynamic multi-dimensional array in C#?

I need to be able to create an array that stores the userid of all users in a room with the current x, y, z position that they are in. I assume I will need to use ArrayList, but I'm not sure how to go about setting it up so that this will work like I'm thinking.

Example:

[0] => user1
  [0] => 20
  [1] => 25
  [2] => 15
[1] => user2
  [0] => 27
  [1] => 25
  [2] => 65

As long as you're not developing for the iPhone, you'll want to use the generic "List". Otherwise, Arraylist is fine.

The syntax for both is pretty similar:

List<Vector3> myVecs = new List<Vector3>();
myVecs.Add(new Vector3(0.5f, 1.0f, 0.3f));

Vector3 firstVec = myVecs[0];

Or

ArrayList myVecs = new ArrayList();
myVecs.Add(new Vector3(0.5f, 1.0f, 0.3f));

Vector3 firstVec = (Vector3)myVecs[0];

The big difference is with generics (like List<>) you can specify the data type that it holds and it will enforce that. It can save you from making stupid mistakes and speeds up processing because it always knows what its working with.

ArrayLists always hold the "Object" data-type. Fortunately, everything derives from that type, so you're always set. You can just add anything to an ArrayList. Of course, then you suffer from "boxing" and "un-boxing" slowdowns, which is just a fancy way of saying the slowdown that happens when your data is converted to a generic "Object" when its added, then back to the actual data type (in this case Vector3) when you need it.

You could alternatively go with a Dictionary or Hashtable - both of them are similar, though Dictionary is the Generic (more strictly typed) version

The idea is that you store a key value pair, in this case the key would be the userid, the value would be the vector position

You can then use the userid to get/set the value easily

example:

`
Dictionary users = new Dictionary();
users["bob"] = new Vector3(1,2,3);
users["jeff"] = Vector3.zero;

Debug.Log(users["bob"]); //this would print <1,2,3>

`

and example for hashtable:

`
Hashtable users = new Hashtable();
users["bob"] = new Vector3(1,2,3);
users["jeff"] = Vector3.zero;

Debug.Log(users["bob"]); //this would print <1,2,3>

`

although it looks like hashtable has less to type here, it's not always the case - you often have to cast the output from it