VB.Net List Distinct and ToList methods not recognized by the compiler. RRS feed

  • Question

  • User2023521679 posted

    I have a function that takes a input string of e-mail addresses which could be separated by various characters and may contain duplicates. My function sorts, removed duplicates and returns a comma delimited list. This works great in two web applications that I have. I tried adding similar code to a windows forms application and it doesn't recognize the .Distinct method or the .ToList. I am targeting .net framework 4.0 in my compile tab. Please advise.

       Function SplitSortRemoveDuplicates(ByVal InputString As String, Optional ByVal ListSeparator As String = ", ") As String
          Dim EMailAddressListSplitCharacters As Char() = {CChar(" "), CChar(","), CChar(";"), Chr(10)}
          Dim StringList As List(Of String) = InputString.Split(EMailAddressListSplitCharacters, StringSplitOptions.RemoveEmptyEntries).Distinct(StringComparer.InvariantCultureIgnoreCase).ToList
          Return String.Join(ListSeparator, StringList)
       End Function

    Tuesday, February 17, 2015 5:25 PM


  • User2023521679 posted

    Solved it. I had to add

    Imports System.Linq in my code.

    It's amazing how I can't find an answer to something until I finally break down and ask others for help.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 17, 2015 5:38 PM