(CheckBox)lstControls.Where(x => x.ID == "some_id").SingleOrDefault();
不到預期的效果:
(CheckBox)lstControls.SingleOrDefault(x => x.ID == "some_id");
而且對於形成不那麼良好的XML文檔,你只知道您正在尋找該元素的名稱是對此最好的語句,您可以用找到的元素:
var xmlElem = (from n in xDocument.Descendants() where (string)n.Attribute("name") == "some_node_name" select n).SingleOrDefault();
感謝....
該死,我不知道SOD有超負荷。進入工具箱! – Will 2009-01-28 15:01:36