Converting XmlNodeList to List<string>
Yes, it's possible using LINQ:
var memberNames = membersIdList.Cast<XmlNode>()
.Select(node => node.InnerText)
.Select(value => int.Parse(value))
.Select(id => library.GetMemberName(id))
.ToList();
Cast<XmlNode>()
call is necessary, because XmlNodeList
does not implement generic IEnumerable<T>
, so you have to explicitly convert it to generic collection from non-generic IEnumerable
.
And yes, you can merge all Select
calls into one if you want:
var memberNames = membersIdList.Cast<XmlNode>()
.Select(x => library.GetMemberName(int.Parse(x.InnerText)))
.ToList();
Why don't you use LINQ to XML
?
List<string> memberNames = XDocument.Load("path")
.XPathSelectElements("//SqlCheckBoxList/value")
.Select(x => library.GetMemberName((int)x))
.ToList();