Collections are used to store, manage, and manipulate groups of related objects in C#. ArrayList is a non-generic collection from the System.Collections namespace that can store elements of different types and dynamically resize as elements are added or removed.
Collections are used to store, manage, and manipulate groups of related objects in C#. They provide a way to work with data in a more flexible and efficient manner compared to arrays.
Collections can be broadly categorized into two types: non-generic collections and generic collections.
Non-generic collections found in the System.Collections namespace can store any type of object, but they lack type safety and may require casting when retrieving elements.
Generic collections found in the System.Collections.Generic namespace provide type safety and better performance by allowing you to specify the type of elements they can hold.
Commonly used collection types include List, Dictionary<TKey, TValue>, Queue, Stack, HashSet, and LinkedList.
Common methods in collections include Add(item), Remove(item), Clear(), Contains(item), and Count.
ArrayList is a non-generic collection that can store elements of any type. It is part of the System.Collections namespace.
ArrayList provides dynamic resizing, allowing you to add or remove elements without worrying about the underlying array size.
Since ArrayList is non-generic, it lacks compile-time type safety and may require casting when retrieving elements.
ArrayList is generally less efficient than generic collections such as List<T> when value types are used because boxing and unboxing may occur.
> "Elements count in ArrayList: 5"> "Elements count in ArrayList: 4"> "The ArrayList elements are:"> "10"> "20"> "Sathesh"> "40.5"
Import System.Collections because ArrayList belongs to the System.Collections namespace.
Create an ArrayList object using new ArrayList().
Use Add() to add integer, string, and decimal values to the ArrayList.
Use Insert(1, 15) to insert the value 15 at index 1. Existing elements from that position are shifted to the right.
Use the Count property to display the number of elements in the ArrayList.
Use Remove(15) to remove the first occurrence of the value 15.
Use a foreach loop to access and display every element in the ArrayList.
An ArrayList can be used in a simple application when a collection needs to hold values of different types, such as numeric values and text, and the number of elements is not known in advance.
ArrayList is a non-generic collection in the System.Collections namespace that can store elements of different types.
ArrayList does not specify an element type using generic type parameters and can therefore store objects of different types.
ArrayList is available in the System.Collections namespace.
ArrayList is non-generic and does not provide compile-time type safety, while List<T> is generic and provides type safety and generally better performance.
The Count property returns the number of elements in an ArrayList.
Insert() adds an element at a specified index and shifts existing elements to the right.
1. ArrayList belongs to which namespace?
2. ArrayList is a:
3. Which method adds an element to the end of an ArrayList?
4. Which method inserts an element at a specified index?
5. What is the value of arrayList.Count after adding five elements?
6. What is the output of the ArrayList after removing 15?
Create an ArrayList, add different types of values, insert a value at a specified index, remove a value, display the Count property, and iterate through the collection.
