How to list all objects in an arraylist in C#?
In C#, you can use a loop to iterate through all the objects in an ArrayList, and then output each object. Here is an example:
using System;
using System.Collections;
class Program
{
static void Main(string[] args)
{
ArrayList myList = new ArrayList();
myList.Add("Apple");
myList.Add("Banana");
myList.Add("Orange");
foreach (object obj in myList)
{
Console.WriteLine(obj);
}
}
}
In the example above, we created an ArrayList object called myList and added three string objects to it. Then, we iterated through each object in the ArrayList using a foreach loop and used the Console.WriteLine() method to output them to the console.