Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Comments
BC @ CV 16-Jan-13 13:14pm    
That's what lists are for.

Hi,

z3ngew wrote:
like when adding to list

So, why you don't use a List?
You can convert a List to an array using the ToArray method, and you can create a List from an array using this code:
C#
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.
 
Share this answer
 
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
Thomas Daniels 17-Jan-13 11:41am    
Thank you!
z3ngew 16-Jan-13 17:41pm    
Thank you for the advice,
z3ngew
 
Share this answer
 
Array.SetValue(object value, int index);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900