3
votes

I have created a new C++ CLR project in Visual Studio 2015 and wanted to try out using Linq functionality in C++. For this I wanted to include the namespace System::Linq. Unfortunately VS claims

Error   C2039   'Linq': is not a member of 'System' ConsoleApplication1 

This is the whole code:

using namespace System;
using namespace System::Linq;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}

How to get this to work?

1

1 Answers

9
votes

Right-click the References node of your project > Add Reference > select System.Core

That this assembly is not included by default by the project template you used to start the project is somewhat logical. Linq code works most smoothly in a language that supports lambda expressions and query comprehensions. C++/CLI is not such a language. Moving that code into a C# class library project that you reference in your C++/CLI project is not a bad idea.