473,396 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Arraylist syntax Question tia sal

sal
Greets,

I'm trying to access individual records and fields of records in an
arraylist
but I'm having trouble. I thinks it's a syntax problem.

Why doesn't arraylist.age(1) give me '67' in the example below
what's the proper syntax? Can arraylist do this or do I have to switch to
a plan array?

Example
Name: Age: Ht:
john 14 56
sally 67 43
bill 34 76
Tia
Nov 21 '05 #1
5 1157
Sal,

I thought that I had seen this before and gave you a sample with a
datatable.

Why using such a complex working array or arraylist in this kind of
situations, while the datatable does it direct for you?.

Cor
"sal" <sa*@spp.net>
Greets,

I'm trying to access individual records and fields of records in an
arraylist
but I'm having trouble. I thinks it's a syntax problem.

Why doesn't arraylist.age(1) give me '67' in the example below
what's the proper syntax? Can arraylist do this or do I have to switch to
a plan array?

Example
Name: Age: Ht:
john 14 56
sally 67 43
bill 34 76
Tia

Nov 21 '05 #2
What order where they placed into the ArrayList. is the array in reverse?
"sal" <sa*@spp.net> wrote in message
news:Xn**********************@216.77.188.18...
Greets,

I'm trying to access individual records and fields of records in an
arraylist
but I'm having trouble. I thinks it's a syntax problem.

Why doesn't arraylist.age(1) give me '67' in the example below
what's the proper syntax? Can arraylist do this or do I have to switch to
a plan array?

Example
Name: Age: Ht:
john 14 56
sally 67 43
bill 34 76
Tia

Nov 21 '05 #3
Hi,

You can't call directly upon properties of objects inside an arraylist,
you need to cast the object back to its original type first.

C#:
((Record)arraylist[1]).age would be 67 assuming you put Record objects
with an age property inside the ArrayList.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 21 '05 #4
What does the addtion to the arraylist look like.
Assume you have a class Example with three properties Name, Age, Ht
respectively.
//I'm assuming an overloaded constructor that accepts three agruments
Example ex = new Example, ("john", 14, 56);
Example ex2 = new Example("sally", 67, 43);
Example ex3 = new Example("bill", 34, 76);

ArrayList al = new ArrayList();
al.Add(ex);
al.Add(ex2);
al.Add(ex3);

int i = ((Employee)al[1]).Age; will work for you or in VB.nET

Dim i as Integer = CType(al(1), Employee).Age

HTH,

Bill
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"sal" <sa*@spp.net> wrote in message
news:Xn**********************@216.77.188.18...
Greets,

I'm trying to access individual records and fields of records in an
arraylist
but I'm having trouble. I thinks it's a syntax problem.

Why doesn't arraylist.age(1) give me '67' in the example below
what's the proper syntax? Can arraylist do this or do I have to switch to
a plan array?

Example
Name: Age: Ht:
john 14 56
sally 67 43
bill 34 76
Tia

Nov 21 '05 #5
Correct syntax will be
arraylist[1]

Regards,

Deepak
[I Code, therefore I am]
"sal" wrote:
Greets,

I'm trying to access individual records and fields of records in an
arraylist
but I'm having trouble. I thinks it's a syntax problem.

Why doesn't arraylist.age(1) give me '67' in the example below
what's the proper syntax? Can arraylist do this or do I have to switch to
a plan array?

Example
Name: Age: Ht:
john 14 56
sally 67 43
bill 34 76
Tia

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jens Stjärna | last post by:
Hi. I have a question regarding the ArrayList. In my code I use the arraylist to store objects of certain class. I do not mix object types in the same ArrayList. public ArrayList adresses = new...
1
by: Kevin P. Fleming | last post by:
ArrayList implements an overload for IEnumerator's GetEnumerator method as follows: GetEnumerator(int offset, int count) However, I can't see a way to take advantage of this, even though I'd...
3
by: SpotNet | last post by:
Hi NewsGroup; Trying to construct a Multidimensional (2D more specifically) populated from an OleDbDataReader. Reason I'm using an ArrayList is I do not know the size of the first dimension...
1
by: Jack Addington | last post by:
I have a method that takes an array of nodes (UltraNode) as a parameter. I've got an arrayList of objects that I am trying to convert to UltraNodes and pass to the method but I cannot seem to get...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
4
by: Fabri | last post by:
Please can u tell me why this code does not work: <%@ Control Language="VB" ClassName="WebUserControl" %> <script runat="server"> ' To create an ArrayList, first, we must dimension it: ...
3
by: mosscliffe | last post by:
Newbie struggling with VB.NET I wish to create an arraylist of structures. I am very new to this coding syntax, so bear with my poor syntax - please struct mystruct Fld1 as short Fld2 as...
22
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b =...
13
by: newkhan | last post by:
HI, I have created an array of ArrayList. ArrayList arraylist=new ArrayList; and them assin them the space for( int index=0; index<arraylist.Length; index++ ) { arraylist = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.