Nis*_*ani 0 c# windows-phone-8
您好我有一个数据列表,我想从列表中删除数据但我的代码返回错误,当我删除一次这里的值是我的代码和类错误是 集合被修改; 枚举操作可能无法执行.删除列表项
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; }
}
Run Code Online (Sandbox Code Playgroud)
您应该使用该List.RemoveAll()方法删除与特定谓词匹配的所有元素,如下面的代码片段所示:
List<string> strList = new List<string>()
{
"One",
"Two",
"RemoveMe",
"Three",
"Four"
};
strList.RemoveAll(element => element == "RemoveMe");
Run Code Online (Sandbox Code Playgroud)
这将删除与"RemoveMe"匹配的所有元素.
如果谓词非常复杂,您可以将其放入单独的方法中,如下所示:
strList.RemoveAll(shouldBeRemoved);
...
private static bool shouldBeRemoved(string element)
{
// Put whatever complex logic you want here,
// and return true or false as appropriate.
return element.StartsWith("Remove");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1485 次 |
| 最近记录: |