I'm using .NET 3.5. Why am I still be getting:
does not contain a definition for 'Distinct'
with this code:
using System.Collections.Generic;
//.. . . . . code
List<string> Words = new List<string>();
// many strings added here . . .
Words = Words.Distinct().ToList();
Are you
?
Distinct
is an extension method defined inSystem.Linq.Enumerable
so you need to add that using statement.And don't forget to add a reference to
System.Core.dll
(if you're using VS2008, this has already been done for you).From msdn blog: Charlie Calvert MSDN Blog Link
To use on .net fiddle : --project type: Console
You forgot to add
Distinct
is an extension method that is defined inSystem.Linq.Enumerable
, so you can only call it if you import that namespace.You'll also need to add a reference to
System.Core.dll
.If you created the project as a .Net 3.5 project, it will already be referenced; if you upgraded it from .Net 2 or 3, you'll have to add the reference yourself.