简体   繁体   中英

C# : Remove item from list with condition

I try to remove item from list with condition. But the condition doesn't work and all of items are removed.

This is my source code :

(Session["AnswerDetail"] as List<T_Answer_Detail>).RemoveAll(a=>a.Answer_Detail_ID==det.Answer_Detail_ID);

Is my source code wrong?

Thank you.

Can you try this, it is working for me.

var result = Session["AnswerDetail"] as List<T_Answer_Detail>;

result.RemoveAll(a=>a.Answer_Detail_ID==det.Answer_Detail_ID)

you can do this :

var list = Session["AnswerDetail"] as List<T_Answer_Detail> ;
Session["AnswerDetail"] =list.Remove(list.Where(x=> x.Answer_Detail_ID==det.Answer_Detail_ID))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM