I'm having problems retrieving data from an ArrayList collection using C#. I'm saving a class into an ArrayList. The code works in saving the data, but I don't know how to write the code to retrieve it. I thought that _serviceList [0]._displayName would retrieve the first item, but it fails. How can I view all the items in the ArrayList?
Thanks.
class Service
{
public string _displayName;
public ServiceControllerStatus _status;
public Service ()
{
_displayName = "";
_status = ServiceControllerStatus.Stopped;
}
public Service (string displayName, ServiceControllerStatus status)
{
_displayName = displayName;
_status = status;
}
}
class Program
{
public static ArrayList _serviceList = new ArrayList ();
public Program ()
{
_serviceList = null;
}
static void Main (string [] args)
{
.
.
.
_serviceList.Add (new Service (service.DisplayName, service.Status));
}
// The following code doesn't work.
Console.WriteLine (_serviceList [0]._displayName);
List<Service> services = new List<Service>();