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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:14:17+00:00 2026-06-04T15:14:17+00:00

Below is a simple C++/CLI example. // TestCLR.cpp : main project file. #include stdafx.h

  • 0

Below is a simple C++/CLI example.

// TestCLR.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    System::Collections::Generic::List<String^> TestList;

    for(int i = 0; i < 10 ; i++)
    {
        TestList.Add(i.ToString());
    }

    for each(String^% st in TestList)
    {
        st += "TEST";
        Console::WriteLine(st);
    }

    for each(String^ st in TestList)
    {
        Console::WriteLine(st);
    }

    return 0;
}

I get the following output:

0TEST
1TEST
2TEST
3TEST
4TEST
5TEST
6TEST
7TEST
8TEST
9TEST
0
1
2
3
4
5
6
7
8
9

In short, the values inside TestList do not change even though I am using a tracking pointer to change its value to “TEST”.

What should I modify in the above snippet so that the value is permanently changed?

  • 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-04T15:14:19+00:00Added an answer on June 4, 2026 at 3:14 pm

    You’ve got a System::Collections::Generic::List, which uses a property to access items. You can’t bind a tracking reference to a property, you end up with a reference to a temporary copy of the value instead.

    That code would work for an array, but foreach can’t be used to mutate elements in-place in a container. You’ll need a for loop, because you need the index to overwrite list elements:

    for(int i = 0, cnt = TestList.Count; i < cnt; ++i)
    {
        TestList[i] += "TEST";
        Console::WriteLine(TestList[i]);
    
        // doesn't work right: String^% st = TestList[i];
        // since TestList[i] is not an lvalue, it's a function call to a getter method
    }
    

    Didn’t you get a compiler warning telling you that you were binding a non-const reference to a temporary object?

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

Sidebar

Related Questions

below is my simple code using HTML 5 multiple file upload. All i need
Below is a simple example of using pointer in delphi. Type TRecord1 = Record
Using the simple example below, what is the best way to return results from
Below is a simple example using gtk2hs that adds a label and then a
In the below 'simple' Ajax login example, I'm using JQuery to submit form params
Consider the simple example below of implementing a method in an Enum. One problem
I have the below simple program using boost threads, what would be the changes
Code below is a simple c# function return an int array. I would like
Below is a simple testing code: public class A { protected int m =
I have a simple statement below: if(file_exists('/images/alum/'.$profile['pic'])) echo '/images/alum/'.$profile['pic']; else echo '/images/user_default.jpg'; The file

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.