tags:

views:

148

answers:

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();
+4  A: 
string[] ids = query.Select(x => x.Value).ToArray();
John Fisher
string[] ids = word.Elements("id").Select(x => x.Value).ToArray<string>();
initialZero
Apress: Pro LINQ is a great book for learning some of these xml operations: http://www.apress.com/book/view/9781590597897
Jim Schubert
+1  A: 

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

Matt Breckon