Click here to Skip to main content
11,410,750 members (64,013 online)
Rate this: bad
good
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 7:49am
z3ngew813
Comments
BC @ CV at 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 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:
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 at 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 at 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 at 16-Jan-13 17:38pm
   
Agree, a 5.
—SA
ProgramFOX at 17-Jan-13 11:41am
   
Thank you!
z3ngew at 16-Jan-13 17:41pm
   
Thank you for the advice,
z3ngew
ProgramFOX at 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
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,918
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
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