Click here to Skip to main content
15,886,840 members
Home / Discussions / C#
   

C#

 
GeneralRe: ArrayList Indexing: Help Pin
Colin Angus Mackay24-Apr-04 14:22
Colin Angus Mackay24-Apr-04 14:22 
GeneralRe: ArrayList Indexing: Help Pin
24-Apr-04 16:35
suss24-Apr-04 16:35 
GeneralRe: ArrayList Indexing: Help Pin
Colin Angus Mackay24-Apr-04 14:25
Colin Angus Mackay24-Apr-04 14:25 
GeneralRe: ArrayList Indexing: Help Pin
Jon G24-Apr-04 14:36
Jon G24-Apr-04 14:36 
GeneralRe: ArrayList Indexing: Help Pin
Member 95766524-Apr-04 16:31
Member 95766524-Apr-04 16:31 
GeneralRe: ArrayList Indexing: Help Pin
Member 95766524-Apr-04 17:42
Member 95766524-Apr-04 17:42 
GeneralRe: ArrayList Indexing: Help Pin
Colin Angus Mackay25-Apr-04 1:22
Colin Angus Mackay25-Apr-04 1:22 
GeneralRe: ArrayList Indexing: Help Pin
Jeff Varszegi25-Apr-04 7:05
professionalJeff Varszegi25-Apr-04 7:05 
I suspect that you're getting confused somewhere along the line. Paste the exact code below into your project, run it, and report back:

C#
<br />
			ArrayList itemList = new ArrayList();<br />
			<br />
			itemList.Add("0");<br />
			itemList.Add("1");<br />
			itemList.Add("2");<br />
			itemList.Add("3");<br />
			itemList.Add("4");<br />
			itemList.Add("5");<br />
			itemList.Add("6");<br />
			itemList.Add("7");<br />
			itemList.Add("8");<br />
			itemList.Add("9");<br />
			<br />
			int count = itemList.Count;<br />
			for (int i=0; i < count; i++) {<br />
				Console.WriteLine("Printing Array: {0} and I:{1}", itemList[i], i);<br />
			} <br />


You're probably confused about assigning int variables. I imagine that you take a read of the Count property before you fill the ArrayList, yes? Well, that object is assigned by value, not by reference, because int is a value type. The part where you populate the array is the only piece missing in the information you gave us; notice the ensuing confusion? Next time, I'd include all the code that's probably part of the problem. I'm not being crusty, just trying to give helpful advice. Anyway, notice that above I read Count after filling the data. This is better on performance than reading Count every trip through the loop.

ArrayList is built specifically to replicate the semantics of accessing an array by index, and it uses an array internally to hold its data. It's probably silly to use an enumerator in your case. Enumerators were made so that all lists can be considered just to be implementations of IList.

Your explicit casts are unnecessary, but I left them in.


Regards,

Jeff Varszegi
GeneralAdding a CheckBox column in DataGrid Pin
Jon G24-Apr-04 13:41
Jon G24-Apr-04 13:41 
GeneralRe: Adding a CheckBox column in DataGrid Pin
Heath Stewart25-Apr-04 4:26
protectorHeath Stewart25-Apr-04 4:26 
GeneralRe: Adding a CheckBox column in DataGrid Pin
Jon G25-Apr-04 6:58
Jon G25-Apr-04 6:58 
GeneralRe: Adding a CheckBox column in DataGrid Pin
Heath Stewart25-Apr-04 7:33
protectorHeath Stewart25-Apr-04 7:33 
GeneralRe: Adding a CheckBox column in DataGrid Pin
Appelz26-Apr-04 20:31
Appelz26-Apr-04 20:31 
GeneralGame Programming with C# Pin
Snews24-Apr-04 10:34
Snews24-Apr-04 10:34 
GeneralRe: Game Programming with C# Pin
Heath Stewart24-Apr-04 10:44
protectorHeath Stewart24-Apr-04 10:44 
GeneralRe: Game Programming with C# Pin
Snews24-Apr-04 10:51
Snews24-Apr-04 10:51 
GeneralRe: Game Programming with C# Pin
bjoernen24-Apr-04 11:23
bjoernen24-Apr-04 11:23 
GeneralRe: Game Programming with C# Pin
Judah Gabriel Himango24-Apr-04 13:24
sponsorJudah Gabriel Himango24-Apr-04 13:24 
GeneralRe: Game Programming with C# Pin
CWIZO24-Apr-04 23:56
CWIZO24-Apr-04 23:56 
GeneralRe: Game Programming with C# Pin
Jeff Varszegi25-Apr-04 7:14
professionalJeff Varszegi25-Apr-04 7:14 
GeneralRe: Game Programming with C# Pin
Judah Gabriel Himango27-Apr-04 19:21
sponsorJudah Gabriel Himango27-Apr-04 19:21 
GeneralRe: Game Programming with C# Pin
Jeff Varszegi28-Apr-04 2:11
professionalJeff Varszegi28-Apr-04 2:11 
GeneralRe: Game Programming with C# Pin
leppie25-Apr-04 0:08
leppie25-Apr-04 0:08 
GeneralTanks for the Ansers... Pin
Snews25-Apr-04 3:58
Snews25-Apr-04 3:58 
GeneralTree Data Structure Pin
William Blasko24-Apr-04 9:40
William Blasko24-Apr-04 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.