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# | Check if an array object is equal to another array object
- C# | Object Class
- C# | Class and Object
- C# | Add an object to the end of the ArrayList
- Object and Collection Initializer in C#
- C# | Search in a SortedList object
- Different ways to create an Object in C#
- C# | Getting the index of the specified key in a SortedList object
- C# | Getting index of the specified value in a SortedList object
- C# | Getting the key at the specified index of a SortedList object
- C# | Get an IDictionaryEnumerator object in OrderedDictionary
- Object and Dynamic Array in C#
- C# | Getting the value at the specified index of a SortedList object
- C# | Method returning an object
- C# | Getting the keys in a SortedList object
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.