Siva,
Maybe you missed this small bit of text in the article?
ReDim allows increasing as well as decreasing an array's size. For this, a
new array is created in each instance. The reason for this is that the
VB.NET array is a descendant of the System.Array of the .NET Runtime which
by definition has a fixed size on creation. In C# this is obvious, as is
demonstrated by the following code emulating ReDim:
string[] arrTest = new string[1];
// and now we want to change the size: ReDim arrTest(20)
arrTest = new string[20];
In itself, this is no problem, the trouble starts with Preserve (today's
topic). When using Redim with the Preserve keyword, the old elements are
preserved - as copies in the new array.
From here it wouldn't be that difficult to write a loop that would copy the
original array into the new one...
But why do that when ArrayList already exists was my point.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Siva M" <sh******@online.excite.com> wrote in message
news:e0**************@TK2MSFTNGP15.phx.gbl...
I agree. But, I thought OP used C#, not Visual Basic.
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ex**************@TK2MSFTNGP12.phx.gbl...
Siva,
You can always ReDim the array. One parameter of the ReDim allows you to
ReDim while keeping the old values but there are issues when using ReDim
Preserve as this article points out:
http://www.aspheute.com/english/20001025.asp
You may be better off in the long run to just use an ArrayList anyway.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Siva M" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... You can consider using ArrayList instead of a standard array. ArrayList
allows you to dynamically add items to it.
"Chris Kettenbach" <c_**********@hotmail.com> wrote in message
news:YI********************@giganews.com...
Good morning, Does anyone happen to know if there's a way to make an
array
of the selected items in an asp:ListBox? I know you can loop through and
check the selected property, my question is how do you know how large to
make your array without looping through the list twice.
I had like button_click(object sender, EventArgs e)
{
ListBox lb = (ListBox)Page.FindControl("myListBox");
foreach(ListItem li in lb.items)
{ if (li.Selected)
{ //some code here to populate the array with the li.value }
}
Thanks for any advice.
Chris