2

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter?

List<string> idList = new List<string>();
foreach (XElement idElement in word.Elements("id"))
{
    idList.Add(idElement.Value);
}
string[] ids = idList.ToArray();

It would be similar to this

But I need the XElement.Value parameter

IEnumerable query = ...;
MyEntityType[] array = query.Cast<MyEntityType>().ToArray();
Community
  • 1
  • 1
initialZero
  • 5,817
  • 8
  • 28
  • 38

2 Answers2

7
string[] ids = query.Select(x => x.Value).ToArray();
John Fisher
  • 21,895
  • 2
  • 37
  • 63
2

Use Select(x => x.Value).ToArray()

Matt Breckon
  • 3,294
  • 19
  • 25