collections - Retrieve Data in an ArrayList with C# -



collections - Retrieve Data in an ArrayList with C# -

i'm having problems retrieving info arraylist collection using c#. i'm saving class arraylist. code works in saving data, don't know how write code retrieve it. thought _servicelist [0]._displayname retrieve first item, fails. how can view items in 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 programme { public static arraylist _servicelist = new arraylist (); public programme () { _servicelist = null; } static void main (string [] args) { . . . _servicelist.add (new service (service.displayname, service.status)); } // next code doesn't work. console.writeline (_servicelist [0]._displayname);

if working on .net framework 2.0 or higher utilize list<t> generic , type safe version list, , changing line

public static arraylist _servicelist = new arraylist ();

to

public static list<service> _servicelist = new list<service>();

would solve issue.

but, if working on lower framework 2.0 have explicitly cast object service like:

console.writeline (((service)_servicelist [0])._displayname);

since arraylist homecoming of type object , not service

c# collections arraylist

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -