I can use foreach, so it must implement IEnumerable.
This is actually not the case, but it does not matter here. It implements IEnumerable , but not the IEnumerable<T> that LINQ works with.
What is actually on the list? If this is already a string, you can use:
var selectedItemsList = selectedItems.Cast<string>().ToList();
Or, if these are “any objects” and you want to call ToString , you can use:
var selectedItemsList = selectedItems.Cast<object>() .Select(x => x.ToString()) .ToList();
Note that Cast 's call is why the error message is suggested using an explicitly typed range variable - the query expression starting with from Foo foo in bar will be converted to bar.Cast<Foo>()...
source share