Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:10:35+00:00 2026-05-27T11:10:35+00:00

I’m new to C# but have a strong background in ActionScript 3. In AS3,

  • 0

I’m new to C# but have a strong background in ActionScript 3.

In AS3, you can define an array like so:

var array:Array = [];

And then add unlimited items to that array via push():

array.push(1);

I’ve noticed in C# that you need to define a permanent (I think) length for an array, eg:

string[] array = {"this","has","a","length","of","six"};

Or:

string[] array = new string[6];

If I try add new items to the array that will fall outside of the length of this array, I’ll get an error:

array[6] = "failure";

I’m finding it hard to go from being able to add/remove items from an array freely, to now having to define a maximum length.

I’m not really sure how this should be approached in a game environment when an array could contain anywhere between 0 and 10000 entities.

  1. Do I just make the array length really long to cater for all the realistic amounts of entities I could have?
  2. Is there a different way I should store my entities that should be used in C# that I don’t know of?
  3. Do I write my own class that redeclares the array with a new length and copies the objects from the old array into the new, with 1 free slot left over?

Any suggestions would be helpful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:10:36+00:00Added an answer on May 27, 2026 at 11:10 am

    Arrays are of fixed size in C# as you have found out; Resizing an array references a new array instance of the specified size and copies the items in the array into the newly referenced instance.

    What you are looking for in .NET are the generic collections such as List<T>, where T is a generic type parameter for some type. In the particular case you have highlighted, you would want to use a List<string>

    var strings = new List<string>();
    

    now you can add strings to the collection using Add()

    strings.Add("string to add");
    

    In C#3, collection intializers were introduced so that you can initialize a collection much more succinctly

    var strings = new List<string> { "string1", "string2", "string3" };
    

    When you create an instance of a generic collection, it starts with a default size; the default size for List<T> in .NET 4 is 0, although this is increased to 4 when the first item is added (default sizes may vary across different collection types and framework versions, so it sounds like default size is an implementation detail). Collections are generally resized by the framework using a doubling strategy, that is, when the collection has reached capacity and another item is trying to be added, the collection capacity is usually doubled – this is taken care of in the implementation of the generic collections and something you don’t need to be concerned with.

    When you may want to bear it in mind is when you are adding a known quantity of items to a collection or know an order of magnitude of how many items you’re going to add. In this case, you may consider using the overloaded constructor of List<T> that takes an int for a default size

    var strings = new List<string>(500);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.