473,508 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to generate a variable-length array in C#?

I intend to generate a variable-length array, similar to link lists in plain C. For example, I define the following array

int [] a

Initially I assign 5 elements to the array as

a = new int[5]
for( k = 0; k < 5; k++
a[k] = k

Then I want to expand the array to 7 elements without discarding the original 5 elements. How to do
Nov 16 '05 #1
1 9943
=?Utf-8?B?bW9vbnJpdmVy?= <xi*******@yahoo.com> wrote in
news:78**********************************@microsof t.com:
I intend to generate a variable-length array, similar to link lists in
plain C. For example, I define the following array:
<snip> Then I want to expand the array to 7 elements without discarding the
original 5 elements. How to do?


Create a new array with the new size and copy over the existing elements.
Then replace the existing array with the new one.

Something like:

Int32[] b = new Int32[7];
Array.Copy(a, 0, b, 0, 5);
a = b;

You might want to look at the ArrayList class too.

--
Lasse Vågsæther Karlsen
la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #2

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

Similar topics

6
10385
by: Lars Plessmann | last post by:
how can I generate a mysql timstamp value of the current time? sample: 20040605042505 YYYYMMDDhhmmss is it only possible by concat year.month.day.hours.minutes.seconds or is there any final...
2
2096
by: Petterson Mikael | last post by:
Hi, I have one xml file with many class elements. For each class element I need to generate a new new java file.As it is now I get ( my output ) all classes in one file. Do I control this in the...
3
4460
by: Mikael Petterson | last post by:
Hi, I have the following in my xml file: <attribute name="bbBusState"> I need to generate to the following: public static final String BB_BUS_STATE_ATTR_TYPE.
4
3226
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
3
5522
by: Mohit Gupta | last post by:
How do I generate Big Integers in VB .NET? For example, if I have a number like 98908324328432864872364234623874682342234234242342 that can't be stored in INT64 or INT32 type variable. How...
1
1668
by: lennyw | last post by:
Hi I'm trying to use XSLT to do an xml to xml transformation where the output xml contains summary data on the information in the input xml. I've succesfully done a Muenchian grouping of the...
22
1776
by: Roberto Gori | last post by:
Hi all, i'm looking for a way, a tool or a macro like this: USEFULMACRO(foo, bar, type1 arg1, type2 arg2, ..., typeN argN) to generate the following code: void foo(type1 arg1, type2...
5
1506
by: mortb | last post by:
Hello! I make use of anonymous delegates in my code. For debugging purposes I'd like to generate the code that the delegates describe. Do anyone have an easy way to do this? cheers, mortb
2
7363
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
2
4375
by: Ardeshir | last post by:
I need help to generate Poisson random variable via Inverse Transform .
0
7127
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...
0
7331
Oralloy
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,...
0
7391
jinu1996
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...
1
7054
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...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
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,...
1
5056
isladogs
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...
0
3204
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...
0
1564
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 ...

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.