How to replace word var from C# to C++ Winforms

José Carlos 886 Reputation points
2023-02-18T18:03:42.1666667+00:00

Hi friends.

I manually populated a dictionary <int,String^> with three pairs of values. I'm wanting to show this data in listView. But inside the for each has the word var, which apparently doesn't exist in C++; How to replace this var word so that the routine works?

Define the dictionary like this:: Dictionary<int, String^>^ _dictionary = gcnew Dictionary<int, String^>;

Follow the code below:




Developer technologies C++
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2023-02-18T18:21:42.1466667+00:00

    Try this kind of loops:

    for each( auto p in _dictionary )
    {
       int key = p.Key;
       String^ value = p.Value;
       . . .
    }
    

    To display the values, probably it is possible to use "binding" too.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. José Carlos 886 Reputation points
    2023-02-18T18:29:57.8766667+00:00

    Hi Viorel.

    Congratulations.

    Worked perfectly.

    Again, thank you very much.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.