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
  • 6,197
  • 9
  • 29
  • 38

2 Answers2

7
string[] ids = query.Select(x => x.Value).ToArray();
John Fisher
  • 22,355
  • 2
  • 39
  • 64
2

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

Matt Breckon
  • 3,374
  • 20
  • 26