2

I have an arraylist of string objects, that then gets added into and arraylist of arraylists.

As a java developer I used to use Vectors, I know now defunct but the name sounds great haha!!, I also used ArrayList which both had access to the sub arraylist by means of, for example

ArrayList<String> array1 = new ArrayList<String>();
array.add("test");

ArrayList<ArrayList> array2 = new ArrayList<ArrayList>()
array2.add(array1);

string var = array2.get(1).get(2);

What is this equivilent in C#?

2
  • Did you even do an attempt to search for the answer? List ... Commented Apr 14, 2011 at 14:02
  • You should start to choose answers on your questions Commented Apr 14, 2011 at 16:28

2 Answers 2

7
var array1 = new List<string>();
array1.Add("test");

var array2 = new List<List<string>>();
array2.Add(array1);

var originalString = array2[0][0]; // or array2[1][2] if there's an item there
Sign up to request clarification or add additional context in comments.

Comments

4

You want to use the List<T> generic class:

List<string> array1 = new List<string>();
array1.Add("test");

List<List<string>> array2 = new List<List<string>>();
array2.Add(array1);

string myStr = array2[0][0]; //Whatever indexers you want here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.