1
我不確定如何更新類數組中的字典。 我從xml中的xml加載升級,有更新數據的索引。從xml更新類數組中的數據的最佳方法[C#,Linq,XML]
我會一直更新,根據更新包含在陣列中的每一類中的數據...
我的數據結構是這樣的:
public class ContactData
{
public int UID { get; set; }
public string Status { get; set; }
...
}
從XML我得到這個:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<status>
<update>
<uid>336699</uid>
<state>My new state</state>
</update>
<update>
<uid>123456</uid>
<state>new state</state>
</update>
<update>
<uid>111111</uid>
<state>some state</state>
</update>
</status>
然後,我必須更新ContactData[] contacts
只能通過XML的UID ...
聯繫人可以長度爲1000,xml可以有相同的長度...
如何執行快速更新?
編輯:
我這樣使用:
XDocument doc = XDocument.Load("http://localhost/contact/xml/status.php");
foreach (XElement node in doc.Descendants("update"))
{
var item = contactList.ListBox.Items.OfType<ContactData>().Where(i => i.UserID.ToString() == node.Element("uid").Value);
ContactData[] its = item.ToArray();
if (its.Length > 0) its[0].Data["state"] = node.Element("state").Value;
}
我需要更新一個存在的ContactData [],但我不知道如何做到這一點,沒有遞歸搜索每個元素... – Achilleterzo 2011-03-21 12:22:56
我這樣做我的方式我發佈 – Achilleterzo 2011-03-22 11:08:39