Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IEnumerable to array of parameter

Tags:

c#

linq

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();
like image 604
initialZero Avatar asked Apr 15 '26 11:04

initialZero


1 Answers

string[] ids = query.Select(x => x.Value).ToArray();
like image 53
John Fisher Avatar answered Apr 16 '26 23:04

John Fisher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!