Difference between del, remove and pop on listsAsk a question
List<T> has two methods you can use.
RemoveAt(int index) can be used if you know the index of the item. For example:
Or you can use Remove(T item):
var itemToRemove = resultlist.Single(r => r.Id == 2);
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)
- 5How can I rename git local and remote branch name?
- 1Is it possible to redirect a web page and show the new URL?
- 1What is the difference between "window.onload" and "$(document).ready()"
- 0Difference between Bower and npm?
- 0What is the difference between serialization and marshaling ?
- 0How to get input text and content to same height inside a table?
- 0Entire div color and does not change at the time of hover
- 1C# Value type and reference type
- 0How to remove highlight border in a textarea upon focus
- 3What is the difference between Array and Arraylist?