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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:01:39+00:00 2026-06-13T10:01:39+00:00

List<Box[]> boxesList = new List<Box[]>(); // create a new list that contains boxes Box[]

  • 0
List<Box[]> boxesList = new List<Box[]>(); // create a new list that contains boxes
Box[] boxes = new Box[9];                  // create an array of boxes
boxesList.Add(boxes);                      // add the boxes to the list
boxesList[0][0] = new Box(2, new Point(0, 0)); // change the content of the list
boxes[0] = new Box(1,new Point(0,0));      //  change content of the boxarray

The problem is after initializing the first
element of the boxes array. The boxesList is also changed.
I think the problem is that the box
array is stored as a reference in the list.
Is there a way around this?
So that the boxeslist will not be changed by changing the box array

  • 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-13T10:01:40+00:00Added an answer on June 13, 2026 at 10:01 am

    The problem is after initializing the first element of the boxes array. The boxesList is also changed.

    No, it’s not. The boxesList has exactly the same contents as it had before: a reference to the array of boxes. There’s only one array here. If you change it, whether that’s through boxesList[0] or boxes, you’re changing the same array.

    If you want to take a copy of the array, you need to do so explicitly. It’s up to you whether you create a copy of the array and put the reference to the copy in the list, or copy the array afterwards.

    See my article on reference types and value types for more information, remembering that all array types are reference types.

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

Sidebar

Related Questions

I have a list box control that contains enough items to list them with
i have a list box and i want to add a folder/directory to that
I have a list box that contains a collection of documents that a user
I have a list box that contains a list of WorkItems (from TFS). I
I have a list box that contains items that are represented by a single
I have a list box control that contains key value pairs delimited by an
How to change the width of list box <select id =tagsList class=ui-widget-content ui-corner-all width=100
So I have a list box that displays averages in a table like format
I have a list box that populates with different sets of data based on
I have a List Box hwich is modified in a such a way that

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.