System.Array. does not contain a definition for "ToList"

fearoffours picture fearoffours · Apr 4, 2011 · Viewed 49.3k times · Source

I'm getting the above error on the ToList() line of the code below

if (emailReplyTo != null)
{
  System.Collections.Generic.List<String> replyto
    = emailReplyTo
    // Strip uneccessary spaces
    .Replace(", ", ",")
    .Split(',')
    .ToList();

  request.WithReplyToAddresses(emailReplyTo);
}

I have included using System.Collections; at the top of my file. The target framework is 3.5, so why is this causing an error?

Answer

Andrew Hare picture Andrew Hare · Apr 4, 2011

The ToList method you are looking for is an extension method. Try adding this using directive to the top of your file:

using System.Linq;

By adding this using directive you are indicating to the compiler that any extension methods in that namespace should be imported. It's kind of a shame that there isn't more help from Visual Studio around importing extension methods (ReSharper does this rather nicely).