Search code examples
c#linq.net-3.5extension-methods

.NET List.Distinct


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();

Solution

  • Are you

    using System.Linq;
    

    ?

    Distinct is an extension method defined in System.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).