Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/CLI and using System::Linq not working

Tags:

.net

c++-cli

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?

like image 807
trenki Avatar asked Oct 25 '25 14:10

trenki


1 Answers

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.

like image 152
Hans Passant Avatar answered Oct 28 '25 04:10

Hans Passant