473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

addinng a new element to the array of strings

How dinamically add a new element to Array????
Nov 22 '05 #1
4 1250
Anatol Ciolac <ac*****@ufmoldova.com> wrote:
How dinamically add a new element to Array????


You can't - arrays are fixed length. What you want is an ArrayList.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Anatol Ciolac <ac*****@ufmoldova.com> wrote:
How dinamically add a new element to Array????


You can't - arrays are fixed length. What you want is an ArrayList.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #3
You could always create some kind so static util method that could
handle this; something like...
public static string[] addStringElement( string[] oldArray, string
element )
{
String[] newArray = new String[ oldArray.Length + 1 ];
Array.Copy( oldArray, newArray, oldArray.Length );
newArray[ oldArray.Length ] = element;
return newArray;
}

This may not be as fast as the ArrayList, but would keep the memory
consumption tight...

~harris

"Anatol Ciolac" <ac*****@ufmoldova.com> wrote in message news:<eB*************@tk2msftngp13.phx.gbl>...
How dinamically add a new element to Array????

Nov 22 '05 #4
Harris <mh********@mail.com> wrote:
You could always create some kind so static util method that could
handle this; something like...

public static string[] addStringElement( string[] oldArray, string
element )
{
String[] newArray = new String[ oldArray.Length + 1 ];
Array.Copy( oldArray, newArray, oldArray.Length );
newArray[ oldArray.Length ] = element;
return newArray;
}

This may not be as fast as the ArrayList, but would keep the memory
consumption tight...


Well, it would keep the absolute memory consumption tight, but in
creating more arrays in the first place, it would cause a lot more
memory "churn". It would be far better to use ArrayList while expanding
and then call TrimToSize when everything had been added, if you're
really worried about the extra size.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #5

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

Similar topics

3
by: Anatol Ciolac | last post by:
How dinamically add a new element to Array????
0
by: Anatol Ciolac | last post by:
How dinamically add a new element to Array????
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
One more for today.... As I add more and more lines to my RichTextBox the array that holds its strings gets bigger and bigger and the vertical scroll bar gets smaller and smaller until the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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 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.