SgDotNet
Singapore Professional .NET User Group -For Cool Developers

C# Array Extend Ability ?

rated by 0 users
This post has 17 Replies | 0 Followers

Top 75 Contributor
Posts 27
Noogard Posted: 02-22-2005 10:08 PM
I heard from my friend that array in C# can be extended. I tried to find the .Net framework but no result so far.
Is that true? If yes, how should I do that?
Thanks in advance Smile
Top 10 Contributor
Posts 762

Maybe you can look into C# ArrayList

Regards, Chua Wen Ching Believe in yourself, and you will succeed
Top 75 Contributor
Posts 27
Tks for that.
Well, then the ArrayList class in C# is somehow exactly Vector class in Java [:^)]
Top 10 Contributor
Posts 762
 Noogard wrote:
Tks for that.
Well, then the ArrayList class in C# is somehow exactly Vector class in Java 


Yeah Surprise
Regards, Chua Wen Ching Believe in yourself, and you will succeed
Top 75 Contributor
Posts 27
 chuawenching wrote:
 Noogard wrote:
Tks for that.
Well, then the ArrayList class in C# is somehow exactly Vector class in Java 


Yeah Surprise


Erm, quite disappointed Sad, I thought C# can do something like this:
-----------------------
int arr [] = new int[10];
arr.extend(10); //or something like that
-----------------------
[^o)]
Top 10 Contributor
Posts 1,125
Dissapointed? I think ArrayList provides you with more flexibility and ease...
Blog -> http://www.dotnetjunkies.com/weblog/rohanthomas/ Singapore's Professional .NET User Group Rocks!!!! Yes
Top 10 Contributor
Posts 762
 Noogard wrote:
 chuawenching wrote:
 Noogard wrote:
Tks for that.
Well, then the ArrayList class in C# is somehow exactly Vector class in Java 


Yeah Surprise


Erm, quite disappointed Sad, I thought C# can do something like this:
-----------------------
int arr [] = new int[10];
arr.extend(10); //or something like that
-----------------------



This is not how you use ArrayList!

Check here at msdn

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclasstopic.asp 

If you want to set the number of elements the ArrayList can handle, look at the Capacity member.
Regards, Chua Wen Ching Believe in yourself, and you will succeed
Top 10 Contributor
Posts 1,221
For those using the C# 2.0, there's a new method for arrays called Resize. This method gave rise due to the power of generics.

Here's how you use it.

String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
Array.Resize( ref myArr, myArr.Length + 5 );

The method fingerprint is this.

public static void Resize( T[] array, intnewSize);

This only works in Whidbey.
Regards, triplez ------------------------------ http://triplez.mine.nu/blogs
Top 75 Contributor
Posts 27
 xtreme.net wrote:
Dissapointed? I think ArrayList provides you with more flexibility and ease...

Yeah, I agreed that Vector/ArrayList is more flexible and easier. However, what I expect from array is speed and effiency, and I only need the array to be extendable (all the elements in array is the same type/object).
Top 75 Contributor
Posts 27
 triplez wrote:
For those using the C# 2.0, there's a new method for arrays called Resize. This method gave rise due to the power of generics.

Here's how you use it.

String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
Array.Resize( ref myArr, myArr.Length + 5 );

The method fingerprint is this.

public static void Resize( T[] array, intnewSize);

This only works in Whidbey.


Yeah, this is exactly what I want Stick out tongue

How can I check which version of C# I'm using?
And what is Whidbey? And IDE?  [:^)]
Top 50 Contributor
Posts 39
 Noogard wrote:
 triplez wrote:
For those using the C# 2.0, there's a new method for arrays called Resize. This method gave rise due to the power of generics.

Here's how you use it.

String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
Array.Resize( ref myArr, myArr.Length + 5 );

The method fingerprint is this.

public static void Resize( T[] array, intnewSize);

This only works in Whidbey.


Yeah, this is exactly what I want Stick out tongue

How can I check which version of C# I'm using?
And what is Whidbey? And IDE?  <img src=" />


C# is only available in .Net Framework 2.0, which is currently in Beta 1 (if I'm not wrong).
Whidbey is the codename for the new version of Visual Studio 2005.
Top 10 Contributor
Posts 1,626
 knave wrote:

C# is only available in .Net Framework 2.0, which is currently in Beta 1 (if I'm not wrong).
Whidbey is the codename for the new version of Visual Studio 2005.


C# is one of the .NET languages that has been around since .NET 1.0. In .NET 2.0, it comes with some new features.
Software development made easy with Paladin RAD Framework. Save some trees, use Stickies.NET
Top 25 Contributor
Posts 240
I use a couple of generated classes from a template that implements strongly typed collections.  It implements ICollection, IList and IEnumerable, but it uses a strongly typed array as internal storage.  The capacity is maintained to avoid resizing all the time, as with the ArrayList, but using an array of primitive types instead of objects.

I pass these suckers all over my application! Smile  I guess you will have your reservations about using custom classes for storage of arrays, but it saves me so much time, I may keep them in .net 2.0 Stick out tongue
Top 10 Contributor
Posts 1,221
What's the link to this code?? Sounds interesting.
Regards, triplez ------------------------------ http://triplez.mine.nu/blogs
Top 25 Contributor
Posts 240
I was going to post the link to the utility which I downloaded but the home page has disappeared and it is missing.

Anyway, the generated code for one type is good enough so here is a link to the IntCollection. You can make copies of the class for each primitive type that you want to use.  I think that you only need to change "using T = System.Int32" at the top, and of course replace the class name.

http://web.eject.co.za/gob/IntCollection.cs
Page 1 of 2 (18 items) 1 2 Next > | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems