你好,我有一個數據表,我想從列表中刪除的數據,但我的代碼返回,當我刪除值一個時間,這裏是我的代碼和類 的一個錯誤錯誤是 收集已修改;枚舉操作可能不會執行。刪除列表項從列表中foreach循環返回錯誤刪除項目
boko_data_json ListAvailableData = Newtonsoft.Json.JsonConvert.DeserializeObject<boko_data_json>(json);
foreach (var item in ListAvailableData.data)
{
string PDFPath = item.downloadpdfpath;
string filename = lastPart.Split('.')[0];
int result = obj.getfile(filename);
if (result == 1)
{
ListAvailableData.data.Remove(item);
}
}
listnameAvailable.ItemsSource = ListAvailableData.data;
} public class boko_data_json
{
// public string Type { get; set; }
public List<Book> data{ get; set; }
public string downloadpdfpath { get; set; }
public string book_name { get; set; }
}
public class Book
{
public int book_id { get; set; }
public string book_name { get; set; }
public string issue_date { get; set; }
public string description { get; set; }
public string status { get; set; }
public string month { get; set; }
public int price { get; set; }
private string forprice { get { return "TL"; } }
public string showprice { get { return price +" "+forprice; } }
private string staticpath { get { return "http://dergiapp.net/"; } }
public string book_image { get; set;}
public string imagepath {get {return staticpath+book_image; }}
public string pdf_path { get; set; }
public string staticpdfpath { get { return "http://dergiapp.net/mobile/test.php?file="; } }
public string downloadpdfpath { get { return staticpdfpath + pdf_path; } }
private string Privewpadf1 { get { return "http://dergiapp.net/zip/p"; } }
private string Privewpadf2 { get { return ".zip"; } }
public string privewpdf { get { return Privewpadf1 + book_id + Privewpadf2; } }
public string download_status { get; set; }
}
您不能從正在由的的foreach – AbZy
可能重複列舉的清單中刪除項目[如何有條件地從.NET集合中刪除項目](http://stackoverflow.com/questions/653596/how-to-conditionally-remove-items-from-a-net-collection) –