Collection<T>.Add(T) method is used to add an object to the end of the Collection<T>.
public void Add (T item);
Here, item is the object to be added to the end of the Collection<T>. The value can be null for reference types.
Below given are some examples to understand the implementation in a better way:
The number of elements in myColl are : 5 The elements in myColl are : A B C D E
The number of elements in myColl are : 4 The elements in myColl are : 2 3 4 5
- Collection<T> accepts null as a valid value for reference types and allows duplicate elements.
- This method is an O(1) operation.
- C# | Add an object to the end of the Queue - Enqueue Operation
- C# | Add an object to the end of the ArrayList
- C# | Add a string to the end of the StringCollection
- C# | Check if an array object is equal to another array object
- C# | Adding the elements of the specified collection to the end of the List
- C# | Copy the elements of a string array to the end of the StringCollection
- C# | Removing the node at the end of LinkedList<T>
- C# | Adding new node or value at the end of LinkedList<T>
- C# | Adding elements to the end of the ArrayList
- C# | Adding the elements to the end of the ArrayList
- How to check whether the index is from start or end in C#?
- Creating an Index From the End of a Collection at a Specified Index Position in C#
- Finding all the Elements of a Range from Start to End in C#
- Finding the End Index of the Specified Range in C#
- How to Create a Range to a Specified End in C#?
- Decimal.Add() Method in C#
- C# | Add element to HashSet
- C# | Add element to SortedSet
- C# | How to add key/value pairs in SortedList
- C# | Add key and value into StringDictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.