0

I have declared an ArrayList like this

Dim List1 As ArrayList = New ArrayList

Adding a ListItem to it

Dim Item As String = ""
List1.Add(New ListItem(Item))

Is there is any limit how many characters the ListItem can contain?

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • 2
    Use a strongly typed `List(Of String)` instead of an `ArrayList`. _"Is there is any limit how many characters Item can contains."_ Your memory is the limit. – Tim Schmelter Sep 24 '12 at 12:02
  • Not that I am aware. Is this a functionality that you want to have? – Ann L. Sep 24 '12 at 12:03

1 Answers1

2

"Is there is any limit how many characters Item can contains." It's limited by the limit of the length of a String and your memory.

The theoretical limit may be 2,147,483,647, but the practical limit is nowhere near that. Since no single object in a .Net program may be over 2GB and the string type uses unicode (2 bytes for each character), the best you could do is 1,073,741,823, but you're not likely to ever be able to allocate that on a 32-bit machine.

https://stackoverflow.com/a/140749/284240

Apart from that, always use a strongly typed List(Of ListItem) instead of an ArrayList.

Dim List1 = New List(Of ListItem)
List1.Add(New ListItem("Foo1"))

c# When should I use List and when should I use arraylist?

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939