[英]Linq to XML -I can do it with listbox but not with a List<>
這是我如何從ListBox形成我的xml
new XElement("City", lstCities.Items
.Cast<ListItem>()
.Select(x => new XElement("TBL_Cities",
new XElement ("CityName",x.Text),
new XElement("TripID",TripID)))
現在也許是因為它快要結束了,但是我不知道如何使用List <>(我的列表lstImages)來完成它,我基本上想將字節文件寫入xml,就像城市(如列表中有1-3個圖像)
這是不起作用的部分
new XElement("TBL_Photo",lstImages
.Cast<byte>()
.Select(x => new XElement("TBL_Photo",
new XElement ("Photo",x),
new XElement("TripID",TripID))))
這將取決於listImages的定義方式,但假設它是List<List<byte>>
,那么就是
new XElement("TBL_Photo",lstImages
//.Cast<byte>() Not needed
.Select(x => new XElement("TBL_Photo",
new XElement ("Photo",x),
new XElement("TripID",TripID))))
這假設XElement允許List作為參數。
您不需要此處的演員表。 您只需要它,因為lstCities.Items是一個ListItemCollection,它沒有實現IEnumerable<ListItem>
。
據我所知,你對List<byte>
代碼大多是正確的。 你有一個不必要的.Cast
調用(但它不會破壞任何東西)。 您的主要問題似乎是括號太多,除非您沒有向我們展示更多代碼。
new XElement("TBL_Photo",
lstImages.Select(x => new XElement("TBL_Photo",
new XElement ("Photo",x),
new XElement("TripID",TripID)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.