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

  • Home
  • SEARCH
  • 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 8729547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:51:11+00:00 2026-06-13T08:51:11+00:00

please see these codes : List<string[]> items_1 = new List<string[]>(); string[] item = new

  • 0

please see these codes :

    List<string[]> items_1 = new List<string[]>();
    string[] item = new string[] { "item_id_for_sell", "item_title", "item_id_main", "item_amount", "item_del_id" };
    items_1.Add(item);
    item[0] = "1";
    item[1] = "1";
    item[2] = "1";
    item[3] = "1";
    item[4] = "1";
    items_1.Add(item);
    item[0] = "2";
    item[1] = "2";
    item[2] = "2";
    item[3] = "2";
    item[4] = "2";
    items_1.Add(item);

i am so confused about this list.
why all string arrays inside that list have “2” value at last?
how can i prevent that list to update itself by updating item (string array)?

thanks in advance

  • 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-13T08:51:12+00:00Added an answer on June 13, 2026 at 8:51 am

    You’re adding a reference to the same array three times, so changing the contents of the array will indeed allow that change to be seen however you get at it. It’s important that you understand that the list doesn’t contain the array itself – it contains references. See my article about reference types and value types for more information.

    You probably just want a new array each time:

    List<string[]> items_1 = new List<string[]>();
    string[] item = { "item_id_for_sell", "item_title",
                      "item_id_main", "item_amount", "item_del_id" };
    items_1.Add(item);
    item = new string[] { "1", "1", "1", "1", "1" };
    items_1.Add(item);
    item = new string[] { "2", "2", "2", "2", "2" };
    items_1.Add(item);
    

    However, I’d urge you to reconsider whether an array of strings is really the best format here. Why not create an Item class with properties Id, Title, Main, Amount and DelId (whatever that means)? Then you can create a List<Item> which will be much easier to work with.

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

Sidebar

Related Questions

Please see my pseudo-code below. The code comments should explain my problem. I'm new
Please see this IBM site - http://www.ibm.com/us/en/ If you see the site banners, there
Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
Please see here , at the end of the post, the 70px author image
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please see this example: if (strlen($_SESSION['userDetails']['THISNAME']) == 0) { $_SESSION['userDetails'][''.$THISNAME.'Error'] = autofocus; include $docRoot/html/forms/reg/user_info.html.php;
Please see below: I tried using Absolute layout, but that's deprecated. I appreciate your
Please see the code snippet below : #include <iostream> using namespace std; int main()
Please see the following manifest. The Activity_1's primary objective has mapInfo refers to a
(Please see update at bottom) I've looked at dozens of questions and haven't been

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.