Click here to Skip to main content
15,888,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear BUDDIES:

Is it possible to define a custom type array such as long array with specefic no. of elements such as 5 and in the run time append its member and extend this array to forexample 9 members?

Yours
Posted
Updated 19-May-12 9:43am
v2

Why not use List[^]? This is more recommended.

As far as resizing the array is concerned. Look here:

http://msdn.microsoft.com/en-us/library/1ffy6686(v=vs.80).aspx[^]
 
Share this answer
 
Comments
Mmohmmad 19-May-12 15:48pm    
dEAR Manas:

Thanks for your answer. What is the benefits of list with respect to array and how should I extend the list?
Wendelius 19-May-12 15:54pm    
My thoughts exactly, +5! :)
Manas Bhardwaj 20-May-12 4:21am    
thanks!
VJ Reddy 20-May-12 1:31am    
Good answer 5!
Manas Bhardwaj 20-May-12 4:21am    
Thanks VJ!
Yes, you can use for example Array.Resize<t>[^] method for this.

However if the amount of elements is unknown, in most scenarios I'd prefer using a List<t>[^]
 
Share this answer
 
Comments
Manas Bhardwaj 19-May-12 17:39pm    
well said. +5
Wendelius 19-May-12 17:44pm    
Thanks Manas :)
VJ Reddy 20-May-12 1:32am    
Good answer 5!
Wendelius 20-May-12 3:06am    
Thanks :)
Of course you can use Linq:

C#
var s =  new string[] { "a", "b", "c" };
var s2 = s.Concat(new string[] { "V" }).ToArray();


or for blank array

C#
var s =  new string[] { "a", "b", "c" };
var s2 = s.Concat(new string[5]).ToArray();


Other solutions also work, and probably faster, but if you are combining arrays, Linq is probably better.
 
Share this answer
 
Comments
Manas Bhardwaj 19-May-12 17:39pm    
nice alternative. my 5!
VJ Reddy 20-May-12 1:32am    
Good answer 5!
Wendelius 20-May-12 3:06am    
LINQ is always fun, my 5

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