I have a Dictionary which Values i wanted to transform into a List. In C# I would use this approach:
var dict = new Dictionary<int, int>();
var list = dict.Values.ToList();
So I wanted to do the same in C++/CLI:
auto dict = gcnew Dictionary<int, int>();
auto list = dict->Values->ToList(); // error C2039
But this doesn't work, because of the error:
Error C2039
'ToList': is not a member of 'System::Collections::Generic::Dictionary<int,int>::ValueCollection'
I don't know, what I am doing wrong, I am new to C++/CLI.
Minimal reproducable example:
#using "System.Linq.dll"
using namespace System::Collections::Generic;
using namespace System::Linq;
int main()
{
auto dict = gcnew Dictionary<int, int>();
auto list = dict->Values->ToList();
}
Compiled with:
cl /clr test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035
for Microsoft (R) .NET Framework version 4.08.4121.0
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(10): error C2039: 'ToList': is not a member of 'System::Collections::Generic::Dictionary<int,int>::ValueCollection'