473,549 Members | 2,745 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 9947
=?Utf-8?B?bW9vbnJpdmV y?= <xi*******@yaho o.com> wrote in
news:78******** *************** ***********@mic rosoft.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
10389
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 function included in PHP to do that for me? I didn't find it, yet.
2
2104
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 code for the transformer or in the xsl-template? Where can I find information about this? Your help is very much appreciated,
3
4464
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
3233
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 name="Banner_error_2"> errormessage 2 for banner </xsl:variable>
3
5532
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 can I generate it? Secondly, how will I multiply 2 big Integers?
1
1676
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 data from the input xml file, but I can't see how to operate on the grouped result to create and output the desired summary data. If someone could give...
22
1792
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 arg2, ..., typeN argN) {
5
1508
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
7370
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 some of our projects. I can configure a project(s) to generate the required XML Documentation file by editing the project properties via VS or I...
2
4376
by: Ardeshir | last post by:
I need help to generate Poisson random variable via Inverse Transform .
0
7450
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...
0
7957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6043
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...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
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...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
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
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.