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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:42:24+00:00 2026-06-03T16:42:24+00:00

When a List<> of primitive types is created in C# (e.g. a List<int> ),

  • 0

When a List<> of primitive types is created in C# (e.g. a List<int>), are the elements inside the list stored by value, or are they stored by reference?

In other words, is C# List<int> equivalent to C++ std::vector<int> or to C++ std::vector<shared_ptr<int>>?

  • 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-06-03T16:42:25+00:00Added an answer on June 3, 2026 at 4:42 pm

    A List<int> will have an int[] internally. No boxing is required usually – the values are stored directly in the array. Of course if you choose to use the List<T> as a non-generic IList, where the API is defined in terms of object, that will box:

    List<int> list1 = new List<int>();
    
    // No boxing or unboxing here
    list1.Add(5);
    int x = list1[0];
    
    // Perfectly valid - but best avoided
    IList list2 = new List<int>();
    
    // Boxed by the caller, then unboxed internally in the implementation
    list2.Add(5);
    
    // Boxed in the implementation, then unboxed by the caller
    int y = (int) list2[0];
    

    Note that the phrase “stored by reference” is a confusing one – the term “by reference” is usually used in the context of parameter passing where it’s somewhat different.

    So while a List<string> (for example) contains an array where each element value is a reference, in a List<int> each element value is simply an int. The only references involved are the callers reference to the List<int>, and the internal reference to the array. (Array types themselves are always reference types, even if the element type is a value type.)

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

Sidebar

Related Questions

I need to provide a user a list of all primitive types available and
Is it possible to use a primitive-typed Collection, such as List<long> , as the
I have in input, which could be a single primitive or a list or
list<int> foo; list<int> foo2; list<int>::iterator foo_end = foo.end(); list<int>::iterator foo2_end = foo2.end(); for (list<int>::iterator
List<Car> oUpdateCar = new List<Car>(); oUpdateCar.Add(new Car()); oUpdateCar[0].name = Color; oUpdateCar[0].value = red; oUpdateCar.Add(new
Why do generics in Java work with classes but not with primitive types? For
I've created a simple auto-complete control using JQuery UI. I have a default value
Possible Duplicate: Why don't Generics support primitive types? Why we cannot use double as
I am curious about the string and primitive types. Article like this says string
What is the list of valid WCF return types? I know some but I

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.