Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

arraylist

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RobcPettit@yahoo.co.uk - 12 Mar 2008 23:07 GMT
Hi, hopefully Ill explain my question ok. Im using an arraylist to get
an an array of values from an application, which allows me to use a
com interface to interact with its functions. I have no access to the
code. I use prices.Add(ba.getPrices());, prices bieng my arraylist. It
returns 1 element, which has 6 dimensions. I think thats the wording.
So within prices[0] there is 6 dimensions, 0 to 5. When I use
prices.count it returns 1, how do I get the count of the dimensions.
Regards Robert
Peter Duniho - 13 Mar 2008 00:46 GMT
> Hi, hopefully Ill explain my question ok. Im using an arraylist to get
> an an array of values from an application, which allows me to use a
[quoted text clipped - 4 lines]
> prices.count it returns 1, how do I get the count of the dimensions.
> Regards Robert

Some actual sample code would be useful here.

It's not really clear what you're trying to do.  But it's possible that  
instead of the Add() method, you really want the AddRange() method.  That  
is, you want the ArrayList to have 6 elements if the array returned by  
"ba.getPrices()" itself has 6 elements.

On the other hand, if you really want to use Add(), that means that your  
ArrayList is eventually going to contain multiple instances of the array  
returned by "ba.getPrices()".  If so, then what you want is to get the  
element from the "prices" array (e.g. "prices[0]") and cast that to the  
appropriate array type, and then look at the Length property of that  
array.  That will tell you how many elements are in the array that was  
returned by "ba.getPrices()" and stored in the "prices" ArrayList.

If neither of the above apply to your use of the ArrayList I think it's  
likely you're misusing the ArrayList.  Again, a code sample would help us  
to better understand the situation and help you fix it.

Pete
RobcPettit@yahoo.co.uk - 13 Mar 2008 07:57 GMT
Thankyou for your reply. Addrange was the one, gives me what I need.
Regards Robert
DSK Chakravarthy - 13 Mar 2008 14:26 GMT
Robert,

Instead of using ArrayList, i recommend you to develop your own class which
is inherited from CollectionBase and implement the .ADD method to it.. so
that you dont have to worry about the index..

HTH,
Chakravarthy

> Hi, hopefully Ill explain my question ok. Im using an arraylist to get
> an an array of values from an application, which allows me to use a
[quoted text clipped - 4 lines]
> prices.count it returns 1, how do I get the count of the dimensions.
> Regards Robert
RobcPettit@yahoo.co.uk - 13 Mar 2008 21:29 GMT
Thankyo for your reply. I will read up on CollectionBase. Im still
having problems, I can see the elements but cant access them.
Regard Robert
RobcPettit@yahoo.co.uk - 13 Mar 2008 23:33 GMT
Im struggling with this. I dont understand why though. If I put a
break in my code and look at the prices array I can see 6 element 0 -
5. If I open up [0] I can see a list of values Im trying to get, they
dont have[0][1] etc beside them, just there names in a column, eg
amount1 100, amount2 200. I thought if I could see them I could ref
them as price[0].amount1. Ive tried object 'o = ba.getprices(0)' and
prices.AddRange(ba.getPrices()). I can see the details in both but
cant get at the details. Im reading up, but Im missing something.
Regards Robert
Jon Skeet [C# MVP] - 13 Mar 2008 23:49 GMT
> Im struggling with this. I dont understand why though. If I put a
> break in my code and look at the prices array I can see 6 element 0 -
[quoted text clipped - 4 lines]
> prices.AddRange(ba.getPrices()). I can see the details in both but
> cant get at the details. Im reading up, but Im missing something.

The debugger is showing you the data dynamically - the compiler only
knows about *static* typing.

However, it would really help if you could show all the code,
highlighting the lines which you're confused about - then we can help.
Comment out any lines which don't work, but you don't know why.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Peter Duniho - 14 Mar 2008 00:01 GMT
> Im struggling with this. I dont understand why though. If I put a
> break in my code and look at the prices array I can see 6 element 0 -
[quoted text clipped - 4 lines]
> prices.AddRange(ba.getPrices()). I can see the details in both but
> cant get at the details. Im reading up, but Im missing something.

Your post is fairly confusing and vague.  However, it sounds like you're  
failing to cast the object stored in the ArrayList back to whatever type  
is returned by the "getPrices()" method you mentioned earlier.

One fix would be to perform that cast so that you can get at the members  
of the actual data structure.  A much better fix would be to use the  
List<T> class instead.  With that, you use whatever type is being returned  
by "getPrices()" (well, the base type for the array that's being returned,  
that is), and then when you reference an element in the List<T>, you  
already have the correct type.

For example, if you've got this:

    class Price
    {
        public decimal amount1 { get; set; }
    }

    Price[] getPrices() { ... }

Then you can declare a variable:

    List<Price> prices = new List<Price>();

Add the new prices:

    prices.AddRange(getPrices());

And access an individual price without casting:

    prices[0].amount1;

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.