-2

Based on the code I see here, my almost-identical code should work:

XDocument doc = XDocument.Parse(stringifiedXML);
var Platypi = doc.Descendants("Platypus").Select(delItem => new
{
    Name = delItem.Element("duckbillName").Value,
    Length = delItem.Element("length").Value,
    Weight = delItem.Element("weight").Value,
    Age = delItem.Element("age").Value,
}).ToList();

Yet instead it violently jerks the rug from under my lazyboy and spills me on the floor, mocking my discomfiture with, "'System.Collections.Generic.IEnumerable' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)"

The question asked may rightly be responded to affirmatively, but right-clicking "Select" does not afford a "Resolve" context menu item, so I don't know what, if anything, I might be missing.

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

2 Answers2

2

You have to add the System.Linq - namespace to use the Select extension method. Select Add Reference and add the System.Core.dll to your project

hmMT
  • 71
  • 1
  • 3
1

Just import the System.Linq namespace with:

using System.Linq;

All LINQ extension methods defined in the Enumerable class which is under the System.Linq namespace.If you are using .NET Framework 4.5.1 version then you should be able to use LINQ methods after you add your reference.

Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • Yes, that did it; I find it odd, or even a bug, that right-clicking "Select" does not afford a "Resolve" context menu item. If you don't know about yourself (.NET), how am I supposed to know about you? After all, I'm not a psychiatrist. – B. Clay Shannon-B. Crow Raven Feb 26 '14 at 22:43
  • 1
    That is not adding a reference. You are merely importing the names of types from other namespaces. – Chris Dunaway Feb 26 '14 at 23:05
  • @ChrisDunaway you are absouletly right.I updated my answer.This is just importing the namespace,a reference to `System.Core.dll` is necessary which is already added by default – Selman Genç Feb 26 '14 at 23:54