473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to increase the size of array and preserve the previous data?

Tee
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
Nov 16 '05 #1
8 10606
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.BlockCop y(array, 0, abytNew, 0, newSize);

return abytNew;

}

Buffer.BlockCop y can handle any type inherited from Array:

byte []
int []
long []

etc...
HTH

"Tee" <th*@streamyx.c om> wrote in message
news:eD******** ******@TK2MSFTN GP10.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

Nov 16 '05 #2
Tee
It will be a string array.

Thanks,
Tee

"mooni" <to*****@hotmai l.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.BlockCop y(array, 0, abytNew, 0, newSize);

return abytNew;

}

Buffer.BlockCop y can handle any type inherited from Array:

byte []
int []
long []

etc...
HTH

"Tee" <th*@streamyx.c om> wrote in message
news:eD******** ******@TK2MSFTN GP10.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


Nov 16 '05 #3
Buffer.BlockCop y also applies to string arrays:

public string [] ReDim(string [] array, int newSize)
{
string [] astrNew = new string[newSize];
Buffer.BlockCop y(array, 0, astrNew, 0, newSize);
return astrNew;
}

HTH
mooni

"Tee" <th*@streamyx.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
It will be a string array.

Thanks,
Tee

"mooni" <to*****@hotmai l.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.BlockCop y(array, 0, abytNew, 0, newSize);

return abytNew;

}

Buffer.BlockCop y can handle any type inherited from Array:

byte []
int []
long []

etc...
HTH

"Tee" <th*@streamyx.c om> wrote in message
news:eD******** ******@TK2MSFTN GP10.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
>
>



Nov 16 '05 #4
Tee
It gives error:

An unhandled exception of type 'System.Argumen tException' occurred in
WindowsApplicat ion10.exe

Additional information: Object must be an array of primitives.

if I comment out this Buffer.BlockCop y, it will work, but can't preserve the
old value.
Thanks.

"mooni" <to*****@hotmai l.com> wrote in message
news:41******@d news.tpgi.com.a u...
Buffer.BlockCop y also applies to string arrays:

public string [] ReDim(string [] array, int newSize)
{
string [] astrNew = new string[newSize];
Buffer.BlockCop y(array, 0, astrNew, 0, newSize);
return astrNew;
}

HTH
mooni

"Tee" <th*@streamyx.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
It will be a string array.

Thanks,
Tee

"mooni" <to*****@hotmai l.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.BlockCop y(array, 0, abytNew, 0, newSize);

return abytNew;

}

Buffer.BlockCop y can handle any type inherited from Array:

byte []
int []
long []

etc...
HTH

"Tee" <th*@streamyx.c om> wrote in message
news:eD******** ******@TK2MSFTN GP10.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
>
>



Nov 16 '05 #5
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.c om> wrote in message
news:O0******** ******@TK2MSFTN GP14.phx.gbl...
It gives error:

An unhandled exception of type 'System.Argumen tException' occurred in
WindowsApplicat ion10.exe

Additional information: Object must be an array of primitives.

if I comment out this Buffer.BlockCop y, it will work, but can't preserve
the
old value.
Thanks.

"mooni" <to*****@hotmai l.com> wrote in message
news:41******@d news.tpgi.com.a u...
Buffer.BlockCop y also applies to string arrays:

public string [] ReDim(string [] array, int newSize)
{
string [] astrNew = new string[newSize];
Buffer.BlockCop y(array, 0, astrNew, 0, newSize);
return astrNew;
}

HTH
mooni

"Tee" <th*@streamyx.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
> It will be a string array.
>
> Thanks,
> Tee
>
> "mooni" <to*****@hotmai l.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.BlockCop y(array, 0, abytNew, 0, newSize);
>>
>> return abytNew;
>>
>> }
>>
>> Buffer.BlockCop y can handle any type inherited from Array:
>>
>> byte []
>> int []
>> long []
>>
>> etc...
>>
>>
>> HTH
>>
>> "Tee" <th*@streamyx.c om> wrote in message
>> news:eD******** ******@TK2MSFTN GP10.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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #6
Tee
I got it to work after I change to Buffer.BlockCop y code to:

System.Array.Co py(array, astrNew, array.Length);

Thanks,

Tee
"Tee" <th*@streamyx.c om> wrote in message
news:O0******** ******@TK2MSFTN GP14.phx.gbl...
It gives error:

An unhandled exception of type 'System.Argumen tException' occurred in
WindowsApplicat ion10.exe

Additional information: Object must be an array of primitives.

if I comment out this Buffer.BlockCop y, it will work, but can't preserve the old value.
Thanks.

"mooni" <to*****@hotmai l.com> wrote in message
news:41******@d news.tpgi.com.a u...
Buffer.BlockCop y also applies to string arrays:

public string [] ReDim(string [] array, int newSize)
{
string [] astrNew = new string[newSize];
Buffer.BlockCop y(array, 0, astrNew, 0, newSize);
return astrNew;
}

HTH
mooni

"Tee" <th*@streamyx.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
It will be a string array.

Thanks,
Tee

"mooni" <to*****@hotmai l.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.BlockCop y(array, 0, abytNew, 0, newSize);
>
> return abytNew;
>
> }
>
> Buffer.BlockCop y can handle any type inherited from Array:
>
> byte []
> int []
> long []
>
> etc...
>
>
> HTH
>
> "Tee" <th*@streamyx.c om> wrote in message
> news:eD******** ******@TK2MSFTN GP10.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
> >
> >
>
>



Nov 16 '05 #7
mooni <to*****@hotmai l.com> wrote:
My mistake, string [] doesn't inherit from System.Array


Um, yes it does...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
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.

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1227
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 check the .HasRows property first then if it is false I skip the data bind like so If OraReader.HasRows Then grdCustomerDetails.AutoGenerateColumns = False grdCustomerDetails.DataSource = OraReader
2
571
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; ... }
3
5321
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.
2
2509
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 the OID of Person), the information of the person matching the selected OID is shown in the Textboxes (Name, Address, id, etc) and the courses this person is taken are shown in a DataGrid (course name, price, etc.). This is working well so far, I...
2
3508
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
5
2460
by: partha.p.das | last post by:
Here is my class: class MyClass { public: MyClass(); ~MyClass(); private:
23
14523
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 the visitors will retype it all so i'm asking: "how to preserve POST-data when clicking the back-button?" i've already tried to print post data as a value in a HTML tag but
1
2765
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 the fixed size using In the attached console application example when I try to address the fields in the class I get an execption.
1
4635
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 increase size of Metabase.xml (In IIS) file up to 1GB. Suppose if i increase size of Metabase.xml file up to 200 MB.is there any problems i can face for other applications ? Why microsoft predefined the size of Metabase.xml file as 4MB ? ...
0
9673
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.