[thelist] C#- using info from an arraylist

Lightning oktellme at earthlink.net
Sat Sep 9 10:26:50 CDT 2006


It works fine now - or at least it compiles!

No need to look at the code I sent you.

Thanks for the help.
Laura

----- Original Message ----- 
From: "Robert Vreeland" <vreeland at studioframework.com>
To: <thelist at lists.evolt.org>
Sent: Saturday, September 09, 2006 10:16 AM
Subject: Re: [thelist] C#- using info from an arraylist


>I was unable to retrieve the file, as the site was to busy - I'll try again
> later. In the mean time, let me try to at least answer some of you
> questions.
>
>>From the code in your post, your foreach loop is assigning a reference to
> each item in the PassengersOnCar collection (array or ArrayList) as a
> Passenger Object - which is not what I think you want to do. What I think
> you were trying to do was get a reference to each ArrayList in the
> PassengersOnCar collection. So you would need to write it like this
>
> foreach(ArrayList intEndFloor in PassengersOnCar)
> //foreach('type of object' 'variable name to use as reference' in 'the
> collection to loop through')
> So, in general, the 'type of object' should be the same type as stored in
> the collection.
>
> Knowing this, you would write your remove statement to use the variable
> reference
>
> PassengersOnCar.Remove(intEndFloor)
>
> This is an expensive proceedure, you are attempting to remove an item by
> value rather then index position and is equivalent to relooping through 
> the
> entire collection. You could get the index position through a counter you
> populate :
>
> Int counter = 0;
> foreach(ArrayList intEndFloor in PassengersOnCar) {
>
> // do stuff
> // if statement
> PassengersOnCar.RemoveAt( counter );
> // end if
> Counter++; // increase counter by 1
>
>
> or by using a for statement
>
> for(int I = 0; I < PassengersOnCar.Count; I++)
> {
> //do stuff
> PassengersOnCar.RemoveAt( I );
>
>
> Hope this helps
> Feel free to email me off list
>
>
> Sincerely,
> Robert Vreeland
> Managing Partner
> StudioFramework
>
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt ! 




More information about the thelist mailing list