INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

how to increment an item array by 1

how to increment an item array by 1

(OP)
I have an item array: A600

I need to increase it by 1 (A601). How do I increase it and have it shown in a textbox?

Thanks

RE: how to increment an item array by 1

If you need to be able to change the size you should really be using a List.

Eg, instead of:

CODE --> C#

string[] ar = new string[600];
ar[0] = "blah";
ar[1] = "blah blah";
.... 

You could do:

CODE --> C#

List<string> ar = new List<string>();
ar.Add("blah");
ar.Add("blah blah"); 

A list uses an array to store its data, so you get the speed of an array with the added benefit of dealing with a linked list.. which means you can add and remove items without worrying about the size.


RE: how to increment an item array by 1

Plus, you can still access the elements of the List like you would the array. In the second example, ar[1] would still return "blah blah" like in the first example.

RE: how to increment an item array by 1

Array.Resize(ref arr, 601);

where arr is your array

www.R-Tag.com Viewer and Scheduler for Crystal reports and SSRS.

RE: how to increment an item array by 1

Keep in mind how one vs. the other works. An Array.Resize actually copies the existing array into a new array. While the List does this as well, it actually maintains excess capacity and then essentially tracks which index you're on. It only resizes once full, doubling capacity each time it does.

If you're dealing with large sets of information where the array is going to need to expand (or contract) on the fly, you're considerably better off using a list; using an array resize each time you need to add a new index is considerably less efficient. If it's just a one off or you're dealing with small sets of data, I suppose it's fine, but you really should just use a List.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close