initialZero
initialZero

Reputation: 6367

IEnumerable to array of parameter

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();

Upvotes: 2

Views: 4407

Answers (2)

Matt Breckon
Matt Breckon

Reputation: 3374

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

Upvotes: 2

John Fisher
John Fisher

Reputation: 22717

string[] ids = query.Select(x => x.Value).ToArray();

Upvotes: 7

Related Questions