Jump to content
  • Advertisement
Sign in to follow this  
Anexa85

vectors in C#?

This topic is 3615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Usually, arraylists (System.Collections.ArrayList or more recently System.Collections.Generic.ArrayList System.Collections.Generic.List).

Share this post


Link to post
Share on other sites
System.Collections.Generic.ArrayList Is the closest thing to a linked list that you can get in C# with out creating your own classes and functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Usually, arraylists (System.Collections.ArrayList or more recently System.Collections.Generic.ArrayList).


Don't use ArrayList anymore. It's outdated, and performs poorly when used with value types (constant boxing and unboxing).

The new version that makes use of generics is System.Collections.Generic.List<T>, and takes the type of the objects in the list as the generic parameter.

Also, using arrays in C# isn't looked down upon like it is in C++. Arrays in C# are safe and easy to use, and don't suffer from the many problems that afflict their C++ counterparts.

Share this post


Link to post
Share on other sites
Thanks for the replies. So you're saying I should just use arrays then? I know in C++ that arrays are not good for a lot of situations where the elements have to be manipulated a lot, moved around, or that need to change in size. Do arrays in C# handle this or something?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anexa85
Thanks for the replies. So you're saying I should just use arrays then? I know in C++ that arrays are not good for a lot of situations where the elements have to be manipulated a lot, moved around, or that need to change in size. Do arrays in C# handle this or something?


No, arrays are still fixed size in C#. If you don't know the size of the list, but just need to add or remove objects on the fly, List<T> will be your best bet.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike.Popoloski
Don't use ArrayList anymore. It's outdated, and performs poorly when used with value types (constant boxing and unboxing).


Darn, I thought for a second there that the generic version was still called 'ArrayList' (like in Java, where 1.5 introduced a generic ArrayList). I did mean the generic System.Collections.Generic.List, too. I apologize for the confusion.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by Mike.Popoloski
Don't use ArrayList anymore. It's outdated, and performs poorly when used with value types (constant boxing and unboxing).


Darn, I thought for a second there that the generic version was still called 'ArrayList' (like in Java, where 1.5 introduced a generic ArrayList). I did mean the generic System.Collections.Generic.List, too. I apologize for the confusion.


No problem, I noticed it right away, I just wanted to make sure that the OP didn't get confused. After GoogolPL3X posted the same thing, I began to wonder if there actually was such a thing as a generic ArrayList. A quick Google solved the problem, however. [smile]

Share this post


Link to post
Share on other sites
Judging from the design of .NET, I suspect that they though it was too confusing to have an ArrayList container but no other kind of list (besides, for cache reasons, in a reference-semantics language an ArrayList will generally behave faster than a LinkedList anyway) and decided to call it a plain old List.

Share this post


Link to post
Share on other sites
Quote:
Original post by Googol PL3X
System.Collections.Generic.ArrayList Is the closest thing to a linked list that you can get in C# with out creating your own classes and functions.


BTW, besides the name, List and ArrayList are not linked list. If you need linked list behaviour go for System.Collections.Generic.LinkedList.

Regards,
Andre

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!