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 6839867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:46:16+00:00 2026-05-26T23:46:16+00:00

I recently did some rough performance measuring on List<> vs [] for an array

  • 0

I recently did some rough performance measuring on List<> vs [] for an array of small structures. System.Array seemed to win hands down so I went with that.

It’s only just dawned on me that System.Array contains object types, so surely filling it with structures would cause boxing to occur?

However, the MSDN entry for System.Array states:

In the .NET Framework version 2.0, the Array class implements the
System.Collections.Generic.IList<T>,
System.Collections.Generic.ICollection<T>, and
System.Collections.Generic.IEnumerable<T> generic interfaces. The
implementations are provided to arrays at run time, and therefore are
not visible to the documentation build tools. As a result, the generic
interfaces do not appear in the declaration syntax for the Array
class, and there are no reference topics for interface members that
are accessible only by casting an array to the generic interface type
(explicit interface implementations).

Does this mean that boxing does not occur after all? (And would explain my performance results)

  • 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-26T23:46:17+00:00Added an answer on May 26, 2026 at 11:46 pm

    No using an array does not box if you use the indexer notation.
    e.g.

    new int[2];
    x=[1]=3;
    

    Compiles to the following IL (note the line numbers are irrelevant as they come from some other snippet of code)

    IL_0011: ldc.i4.2
    IL_0012: newarr System.Int32
    IL_0017: stfld Int32[] x
    IL_001c: ldarg.0
    IL_001d: ldfld Int32[] x
    IL_0022: ldc.i4.1
    IL_0023: ldc.i4.3
    IL_0024: stelem.i4
    

    For languages that cannot use the indexer (and I don’t really know if they exist or not) 2 other methods are created at compile time for Arrays.

    It creates these public methods::

    public int Get(int index)
    public void Set(int index,int value)
    

    Those methods don’t box either and are not normally accessible through C#. (Don’t ask me why they are public methods). You can execute them using IL or by creating delegates to them. They are slower as you are forced to do a callvirt to invoke these methods.

    The stelem.* and ldelem.* family is used to handle storing to a strongly typed array type. When using generics usually the following prefixes are attached constrained or readonly when using a T[]. stelem.* type usually do not check type. E.g. using stelem.i4 is faster than using stelem.any Int32 unless you prefix it with readonly because otherwise it forces a type check.

    Now the typecheck is COMPLETELY useless on valuetype arrays are they are not covariant!

    Because the runtime generates the one dimensional array starting at zero (either called SZ_array or vector type) type they are natively known.

    There are a family of il op codes for them: newarr,stelem.*,ldelem.*,ldlen etc.

    The List<T> type uses a T[] for its backing store in the microsoft implementation of the BCL. List<T> does not box. Regardless of using list or array you are storing things in an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently did some performance testing and analysis of an ASP.NET application using out-of-process
I recently did some refactoring of my mvc application and realized that there are
I recently did a big update on my wordpress site, thus some old permalink
I recently did some work modifying a Python gui app that was using wxPython
I've recently did some web design as a hobby with a primary motivation to
Recently downloaded some code for a minor open-source project related to a small webgame
I recently did the Chris Coyier tutorial from the css-tricks.com weblog #38: Basics &
I recently did an online installation of SP1 for VS 2008, where installation of
I recently wrote a piece of code which did SomeClass someObject; mysqlpp::StoreQueryResult result =
Recently our Subversion (SVN) server was changed and we did a svn switch .

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.