Click here to Skip to main content
12,298,927 members (51,926 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hello Everyone,
Is there a method to add items to an array with using index, like when adding to list.
Array.add(item)//for example

Thanks in advance,
z3ngew
Posted 16-Jan-13 6:49am
z3ngew822
Comments
BC @ CV 16-Jan-13 13:14pm
   
That's what lists are for.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

z3ngew wrote:
like when adding to list

So, why you don't use aList
?
You can convert a List to an array using the ToArray method, and you can create a List from an array using this code:
List<int> integerList = new List<int>(integerArray); // create a List from an array
// alternative way: List<int> integerList = integerArray.ToList();
// add some integers
integerArray = integerList.ToArray();
Hope this helps.
  Permalink  
v3
Comments
z3ngew 16-Jan-13 13:57pm
   
I am allready using List, but i'm scared it may cost me more memory
Thanks for your support,
z3ngew
Sergey Alexandrovich Kryukov 16-Jan-13 17:37pm
   
If you managed to use array this way, it will cost you a lot more.
Here is the usual advice for the beginners (and your level is less than the beginner's at the moment, you are the highly confused beginner, just yet): before you get more experience, don't do any assumptions on the cost; it will come later. The very usual mistake is great underestimation of the computer capacity. The opposite happens, but rarely.
—SA
Sergey Alexandrovich Kryukov 16-Jan-13 17:38pm
   
Agree, a 5.
—SA
ProgramFOX 17-Jan-13 11:41am
   
Thank you!
z3ngew 16-Jan-13 17:41pm
   
Thank you for the advice,
z3ngew
ProgramFOX 17-Jan-13 11:41am
   
You're welcome!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Array.SetValue(object value, int index);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100