Is it possible to convert an XmlNodeList to List? without declaring a new List I am looking for a simple implementation for this:
System.Xml.XmlNodeList membersIdList = xmlDoc.SelectNodes("//SqlCheckBoxList/value");
List<string> memberNames = new List<string>();
foreach (System.Xml.XmlNode item in membersIdList)
{
memberNames.Add(library.GetMemberName(int.Parse(item.InnerText)));
}
Yes, it's possible using LINQ:
Cast<XmlNode>()
call is necessary, becauseXmlNodeList
does not implement genericIEnumerable<T>
, so you have to explicitly convert it to generic collection from non-genericIEnumerable
.And yes, you can merge all
Select
calls into one if you want:Why don't you use
LINQ to XML
?