Hi,
How do we increase the size of array on runtime and preserve the previous
data?
I don't want to use ArrayList because the array could be a multi-dimension
array.
Thanks,
Tee 8 10582
You didn't specify what type of array but for a byte array you could use the
following method:
public byte [] ReDim(byte [] array, int newSize)
{
byte [] abytNew = new byte[newSize];
Buffer.BlockCopy(array, 0, abytNew, 0, newSize);
return abytNew;
}
Buffer.BlockCopy can handle any type inherited from Array:
byte []
int []
long []
etc...
HTH
"Tee" <th*@streamyx.com> wrote in message
news:eD**************@TK2MSFTNGP10.phx.gbl... Hi,
How do we increase the size of array on runtime and preserve the previous data? I don't want to use ArrayList because the array could be a multi-dimension array.
Thanks, Tee
It will be a string array.
Thanks,
Tee
"mooni" <to*****@hotmail.com> wrote in message
news:41********@dnews.tpgi.com.au... You didn't specify what type of array but for a byte array you could use
the following method:
public byte [] ReDim(byte [] array, int newSize)
{
byte [] abytNew = new byte[newSize];
Buffer.BlockCopy(array, 0, abytNew, 0, newSize);
return abytNew;
}
Buffer.BlockCopy can handle any type inherited from Array:
byte [] int [] long []
etc...
HTH
"Tee" <th*@streamyx.com> wrote in message news:eD**************@TK2MSFTNGP10.phx.gbl... Hi,
How do we increase the size of array on runtime and preserve the
previous data? I don't want to use ArrayList because the array could be a
multi-dimension array.
Thanks, Tee
Buffer.BlockCopy also applies to string arrays:
public string [] ReDim(string [] array, int newSize)
{
string [] astrNew = new string[newSize];
Buffer.BlockCopy(array, 0, astrNew, 0, newSize);
return astrNew;
}
HTH
mooni
"Tee" <th*@streamyx.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... It will be a string array.
Thanks, Tee
"mooni" <to*****@hotmail.com> wrote in message news:41********@dnews.tpgi.com.au... You didn't specify what type of array but for a byte array you could use the following method:
public byte [] ReDim(byte [] array, int newSize)
{
byte [] abytNew = new byte[newSize];
Buffer.BlockCopy(array, 0, abytNew, 0, newSize);
return abytNew;
}
Buffer.BlockCopy can handle any type inherited from Array:
byte [] int [] long []
etc...
HTH
"Tee" <th*@streamyx.com> wrote in message news:eD**************@TK2MSFTNGP10.phx.gbl... > Hi, > > How do we increase the size of array on runtime and preserve the previous > data? > I don't want to use ArrayList because the array could be a multi-dimension > array. > > > Thanks, > Tee > >
It gives error:
An unhandled exception of type 'System.ArgumentException' occurred in
WindowsApplication10.exe
Additional information: Object must be an array of primitives.
if I comment out this Buffer.BlockCopy, it will work, but can't preserve the
old value.
Thanks.
"mooni" <to*****@hotmail.com> wrote in message
news:41******@dnews.tpgi.com.au... Buffer.BlockCopy also applies to string arrays:
public string [] ReDim(string [] array, int newSize) { string [] astrNew = new string[newSize]; Buffer.BlockCopy(array, 0, astrNew, 0, newSize); return astrNew; }
HTH mooni
"Tee" <th*@streamyx.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... It will be a string array.
Thanks, Tee
"mooni" <to*****@hotmail.com> wrote in message news:41********@dnews.tpgi.com.au... You didn't specify what type of array but for a byte array you could
use the following method:
public byte [] ReDim(byte [] array, int newSize)
{
byte [] abytNew = new byte[newSize];
Buffer.BlockCopy(array, 0, abytNew, 0, newSize);
return abytNew;
}
Buffer.BlockCopy can handle any type inherited from Array:
byte [] int [] long []
etc...
HTH
"Tee" <th*@streamyx.com> wrote in message news:eD**************@TK2MSFTNGP10.phx.gbl... > Hi, > > How do we increase the size of array on runtime and preserve the previous > data? > I don't want to use ArrayList because the array could be a multi-dimension > array. > > > Thanks, > Tee > >
My mistake, string [] doesn't inherit from System.Array
Try:
public string [] ReDim(string [] array, int newSize)
{
string [] abytNew = new string[newSize];
for(int iCounter = 0; iCounter < array.Length; iCounter++)
abytNew[iCounter] = array[iCounter];
return abytNew;
}
HTH
mooni
"Tee" <th*@streamyx.com> wrote in message
news:O0**************@TK2MSFTNGP14.phx.gbl... It gives error:
An unhandled exception of type 'System.ArgumentException' occurred in WindowsApplication10.exe
Additional information: Object must be an array of primitives.
if I comment out this Buffer.BlockCopy, it will work, but can't preserve the old value.
Thanks.
"mooni" <to*****@hotmail.com> wrote in message news:41******@dnews.tpgi.com.au... Buffer.BlockCopy also applies to string arrays:
public string [] ReDim(string [] array, int newSize) { string [] astrNew = new string[newSize]; Buffer.BlockCopy(array, 0, astrNew, 0, newSize); return astrNew; }
HTH mooni
"Tee" <th*@streamyx.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... > It will be a string array. > > Thanks, > Tee > > "mooni" <to*****@hotmail.com> wrote in message > news:41********@dnews.tpgi.com.au... >> You didn't specify what type of array but for a byte array you could use > the >> following method: >> >> public byte [] ReDim(byte [] array, int newSize) >> >> { >> >> byte [] abytNew = new byte[newSize]; >> >> Buffer.BlockCopy(array, 0, abytNew, 0, newSize); >> >> return abytNew; >> >> } >> >> Buffer.BlockCopy can handle any type inherited from Array: >> >> byte [] >> int [] >> long [] >> >> etc... >> >> >> HTH >> >> "Tee" <th*@streamyx.com> wrote in message >> news:eD**************@TK2MSFTNGP10.phx.gbl... >> > Hi, >> > >> > How do we increase the size of array on runtime and preserve the > previous >> > data? >> > I don't want to use ArrayList because the array could be a > multi-dimension >> > array. >> > >> > >> > Thanks, >> > Tee >> > >> > >> >> > >
I got it to work after I change to Buffer.BlockCopy code to:
System.Array.Copy(array, astrNew, array.Length);
Thanks,
Tee
"Tee" <th*@streamyx.com> wrote in message
news:O0**************@TK2MSFTNGP14.phx.gbl... It gives error:
An unhandled exception of type 'System.ArgumentException' occurred in WindowsApplication10.exe
Additional information: Object must be an array of primitives.
if I comment out this Buffer.BlockCopy, it will work, but can't preserve
the old value.
Thanks.
"mooni" <to*****@hotmail.com> wrote in message news:41******@dnews.tpgi.com.au... Buffer.BlockCopy also applies to string arrays:
public string [] ReDim(string [] array, int newSize) { string [] astrNew = new string[newSize]; Buffer.BlockCopy(array, 0, astrNew, 0, newSize); return astrNew; }
HTH mooni
"Tee" <th*@streamyx.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... It will be a string array.
Thanks, Tee
"mooni" <to*****@hotmail.com> wrote in message news:41********@dnews.tpgi.com.au... > You didn't specify what type of array but for a byte array you could use the > following method: > > public byte [] ReDim(byte [] array, int newSize) > > { > > byte [] abytNew = new byte[newSize]; > > Buffer.BlockCopy(array, 0, abytNew, 0, newSize); > > return abytNew; > > } > > Buffer.BlockCopy can handle any type inherited from Array: > > byte [] > int [] > long [] > > etc... > > > HTH > > "Tee" <th*@streamyx.com> wrote in message > news:eD**************@TK2MSFTNGP10.phx.gbl... > > Hi, > > > > How do we increase the size of array on runtime and preserve the previous > > data? > > I don't want to use ArrayList because the array could be a multi-dimension > > array. > > > > > > Thanks, > > Tee > > > > > >
mooni <to*****@hotmail.com> wrote: My mistake, string [] doesn't inherit from System.Array
Um, yes it does...
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Could you give a broader statement of your original problem? What are
you trying to do? ArrayList is quite capable of supporting
multi-dimensional arrays, but it all depends upon what you want to do
with the arrays and how you want them to work. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jawahar Rajan |
last post by:
All,
I have a datagrid that I use in a ASP.net web page that loads customer data
based on the selected customer ID
Some Customers will have no data in the database (which is oracle 9.2) . So
I...
|
by: nospam |
last post by:
Hello!
I can pass a "pointer to a double" to a function that accepts
double*, like this:
int func(double* var) {
*var=1.0;
...
}
|
by: Tee |
last post by:
Hi,
Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.
Thanks.
|
by: Josef Meile |
last post by:
Hi,
I'm using a ComboBox, some Textboxes, and a DataGrid to represent a
many-to-many relationship between Person and Course. Each time that I change
the value in the ComboBox (which for now is...
|
by: yoshitha |
last post by:
Hi
Can any one tell me how to increase size of an array in C#.net with ASP.Net?
its very urgent for me
thanks
yoshitha
|
by: partha.p.das |
last post by:
Here is my class:
class MyClass {
public:
MyClass();
~MyClass();
private:
|
by: Bjorn |
last post by:
Hi.
Every time i post data in a form the contents are being checked for
validity.
When i click the back-button, all data is gone and i have to retype it.
It's obvious that only a few or none of...
|
by: shofu_au |
last post by:
Hi Group,
I am trying to define a class that has a fixed size array of a
structure containing a fixed size array of a structure.
I am using System.Runtime.InteropServices and trying to define...
|
by: nagmvs |
last post by:
Hello
I am unable to upload More than 200kb in to my server and also i can downlaod only less than 4MB file from my server .When i am searching in internet i found solution as u can...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |