Count.ToString in ArrayList

  • Thread starter Thread starter Krish
  • Start date Start date
K

Krish

I donot understand why it is this way.

I have an arraylist.

I understand I can get the count by arraylist.count

in .net studio, intellisense also gives me arraylist.count.tostring()
 
COunt is an integer so MessageBox.Show(arraylist.Count); won't compile. If
you want to show what it is, you need to convert it to string and ToString()
is a good way to do it. Depending on the situation, you may need it in some
other form other than int.
 
Hi Krish,

What do you not understand?

An ArrayList is a linked list that can grow and shrink in size when needed.
The ArrayList has a Count property that returns the number of items
"inside" the list.
This number is of type 'int', and the ToString() method will convert it to
'string'.

ArrayList myList = new ArrayList.

int numberInt = myList.Count; // returns 0
string numberString = myList.Count.ToString(); // returns "0";

myList.Count.ToString(); // is the same as
(myList.Count).ToString(); // which in this example is the same as
numberInt.ToString();

It would be much easier to help you if you can give us a clear question.


Happy coding!
Morten Wennevik [C# MVP]
 
Morten Wennevik said:
An ArrayList is a linked list that can grow and shrink in size when needed.

No, an ArrayList is *not* a linked list. It's a list backed by an
array. It can grow and shrink in size when needed - if it exceeds the
bounds of the internal array, a new array is created and the contents
of the old one copied. That is all hidden from the client, however.

<snip stuff I agree with>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top