Arraylist of Hashtables

So, I have an arraylist of hashtables. I know I can get access to them like so.

Hashtable table = (Hashtable)alList[0];
table[“key”].toString();

However, I want to know if there’s a way to access the table without having to assign it.
This is C# by the way.

You can perform the cast inline.

((Hashtable)aList[0])["key"]

Alternatively, you can use a System.Collections.Generic.List, which is the generics counterpart of ArrayList. That way you won’t need to cast.

List<Hashtable> aList = new List<Hashtable>();
aList.Add(new Hashtable());
aList[0]["key"] = 42;
Debug.Log(aList[0]["key"]);

Taking it a step further, you could also use a generics Dictionary instead of a Hashtable. Use whatever makes most sense for you.

This:

((Hashtable)(alList[0]))["key"].ToString();

Jasper beat me to it because I was looking at a cached page. Oh well. :slight_smile: