4
我有這樣的大腦失敗。我選擇的元素,我需要的價值觀,我只是使這個返回匿名類型掙扎:如何將LINQ查詢轉換爲匿名類型
這裏是XML:
<r25:space xl:href="space.xml?space_id=244" id="BRJDMjQ0" crc="00000023" status="est">
<r25:space_id>244</r25:space_id>
<r25:space_name>BEC*103</r25:space_name>
<r25:formal_name>Branson Education Center 103</r25:formal_name>
<r25:partition_id />
<r25:partition_name />
<r25:favorite>F</r25:favorite>
<r25:max_capacity>24</r25:max_capacity>
<r25:fill_ratio />
<r25:last_mod_user>kleierd</r25:last_mod_user>
<r25:last_mod_dt>2009-11-19T15:35:33</r25:last_mod_dt>
</r25:space>
我需要「space_id」和「SPACE_NAME的價值「我可以用這樣得到:
var ids = from id in xml.Descendants()
where id.Name.LocalName == "space_id" || id.Name.LocalName == "space_name"
select (string)id.Value;
但我真的很喜歡這樣的:
var ids = from id in xml.Descendants()
where id.Name.LocalName == "space_id" || id.Name.LocalName == "space_name"
select new
{
theId = //The id val would go here,
theName = //The name goes here
};
人這是偉大的, 謝謝。 –