Why is:
(CheckBox)lstControls.Where(x => x.ID == 'some_id').SingleOrDefault();
not as efficient as:
(CheckBox)lstControls.SingleOrDefault(x => x.ID == 'some_id');
And for a not-so-well-formed XML document and you only know the name of the element you are looking for is this the best statement you can use to find the element:
var xmlElem = (from n in xDocument.Descendants() where (string)n.Attribute('name') == 'some_node_name' select n).SingleOrDefault();
Thanks….
If I’m not mistaken, in terms of big O efficiency, it’s the same. It’s just an extra method call.
Regarding the second question,
can be expressed more simply as