How to retrieve a specific element in an ArrayList in C…
In C#, you can use the index of an ArrayList to access a specific element. Elements in an ArrayList are numbered in the order they were added, starting from 0. To access a specific element, you can use the following code:
ArrayList list = new ArrayList();
list.Add("元素1");
list.Add("元素2");
list.Add("元素3");
object element = list[1]; // 获取第二个元素,索引为1
Console.WriteLine(element); // 输出:元素2
In the example above, we created an ArrayList and added 3 elements to it. Then, we retrieved the second element, “Element 2”, by using an index of 1. Finally, we printed this element to the console using the Console.WriteLine method.