List<T> has two methods you can use.
RemoveAt(int index) can be used if you know the index of the item. For example:
resultlist.RemoveAt(1); Or you can use Remove(T item): var itemToRemove = resultlist.Single(r => r.Id == 2); resultList.Remove(itemToRemove);
When you are not sure, the item really exists, you can use SingleOrDefault. SingleOrDefault will return null if there is no item (Single will throw an exception when it can’t find the item). Both will throw when there is a duplicate value (two items with the same id).
var itemToRemove = resultlist.SingleOrDefault(r => r.Id == 2); if (itemToRemove != null) resultList.Remove(itemToRemove
- 1Bitbucket and Visual Studio
- 1How to dump and restore database in MongoDB
- 1How to compress and extract files/folders using the tar command on Ubuntu
- 5What is "marquee" tag and how I can use it in HTML?
- 1Generating a series of colors between two colors
- 1How To Create a New User and Grant Permissions in MySQL
- 1What is the difference between setTimeout and setInterval?
- 3What's the difference between using “let” and “var”?
- 1Abstract and Virtual Methods
- 1What is PATH, and when to use it in C++
- 1How to make my footer cover 100% height and width of the page from top?