List<T>.ForEach(Action<T>) Method is used to perform a specified action on each element of the List<T>.
Properties of List:
- It is different from the arrays. A list can be resized dynamically but arrays cannot.
- List class can accept null as a valid value for reference types and it also allows duplicate elements.
- If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element.
public void ForEach (Action action);
action: It is the Action<T> delegate to perform on each element of the List<T>.
- ArgumentNullException: If the action is null.
- InvalidOperationException: If an element in the collection has been modified.
Below programs illustrate the use List<T>.ForEach(Action<T>) Method:
Geeks For Geeks GFG C# Tutorials GeeksforGeeks
6 7 8 9 10 11 12
- C# | Performing Specified action on each element of Array
- C# | Removing the specified element from the List
- C# | Gets or Sets the element at the specified index in the List
- C# | How to remove the element from the specified index of the List
- C# | How to get the last occurrence of the element in the List that match the specified conditions
- C# | How to check whether a List contains a specified element
- C# | Insert an element into the ArrayList at the specified index
- C# | Check if a HashSet contains the specified element
- C# | Remove the element with the specified key from the Hashtable
- C# | Remove the specified element from a HashSet
- C# | Remove the element at the specified index of the ArrayList
- C# | Remove the element with the specified key from a SortedList
- C# | Insert an element into Collection<T> at specified index
- C# | Remove element at specified index of Collection<T>
- C# | Get or set the element at the specified index in ArrayList
- C# | Adding the elements of the specified collection to the end of the List
- C# | How to insert the elements of a collection into the List at the specified index
- C# | First occurrence in the List that matches the specified conditions
- C# | How to get all elements of a List that match the conditions specified by the predicate
- C# | How to check whether a List contains the elements that match the specified conditions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.