tags:

views:

313

answers:

1

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....

+1  A: 

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,

var xmlElem = (from n in xDocument.Descendants() where (string)n.Attribute("name") == "some_node_name" select n).SingleOrDefault();

can be expressed more simply as

var xmlElem = xDocument.Descendants().SingleOrDefault(n => (string)n.Attribute("name") == "some_node_name");
configurator
Shit, I didn't know SOD had overloads. into the toolbox!
Will