I'm trying to use LINQ in a C# (Polyglot Notebook).
using System.Linq;
Environment.GetEnvironmentVariables().Values.Select(x => x)
But I'm getting the error:
Error: (3,46): error CS1061: 'ICollection' does not contain a definition for 'Select' and no accessible extension method 'Select' accepting a first argument of type 'ICollection' could be found (are you missing a using directive or an assembly reference?)
You don't need the using statement, LINQ should be available/imported by default. The "issue" here is that
Environment.GetEnvironmentVariables()
returns a non-genericIDictionary
and it'sValues
property is non-genericICollection
(which implements non-genericIEnumerable
) which does not support much of LINQ's methods besidesCast
, most of LINQ works with generic version ofIEnumerable
. So you can useCast
orOfType
: