PC Review


Reply
Thread Tools Rate Thread

Arraylist syntax Question tia sal

 
 
sal
Guest
Posts: n/a
 
      25th Nov 2004
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
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Nov 2004
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" <(E-Mail Removed)>
> 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



 
Reply With Quote
 
MattC
Guest
Posts: n/a
 
      25th Nov 2004
What order where they placed into the ArrayList. is the array in reverse?
"sal" <(E-Mail Removed)> wrote in message
news:Xns95AC4CF98A3Bsalsppnet@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



 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      25th Nov 2004
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]
 
Reply With Quote
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      25th Nov 2004
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" <(E-Mail Removed)> wrote in message
news:Xns95AC4CF98A3Bsalsppnet@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



 
Reply With Quote
 
=?Utf-8?B?RGVlcGFr?=
Guest
Posts: n/a
 
      25th Nov 2004
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList Question Hoop Microsoft C# .NET 8 31st Mar 2008 11:05 PM
ArrayList question JL Microsoft VB .NET 1 26th Nov 2005 05:13 PM
arrayList question NuCoder Microsoft C# .NET 4 16th Jun 2005 05:55 PM
Arraylist syntax Question tia sal sal Microsoft ADO .NET 1 25th Nov 2004 10:31 PM
Arraylist simple question (newbie) OT (for a CF project, but not necessarily a CF question?) Keith R Microsoft Dot NET Compact Framework 1 2nd Dec 2003 10:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.