Skip to main content

Posts

Showing posts with the label arraylist

c# - How to make an ArrayList read-only

Make an ArrayList read-only The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can make an ArrayList read-only. That means we will convert an ArrayList instance to a read-only ArrayList. We also check whether an ArrayList instance is read-only or not. Here we will use the ArrayList class ReadOnly() method to make an ArrayList read-only. We also use the ArrayList class IsReadOnly property to determine whether an ArrayList is read-only or not. A collection that...

c# - How to copy elements over a range in ArrayList

Copy the elements of a collection over a range of elements in an ArrayList The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can copy the elements of a collection over a range of elements in an ArrayList instance. Here we will use the ArrayList class SetRange() method to copy elements over a range of elements in the ArrayList object. The ArrayList SetRange(Int32, ICollection) method copies the elements of a collection over a range of elements in the Array...

c# - How to reverse ArrayList range of elements order

Reverse order of a range of elements in an ArrayList The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can reverse the order of a range of elements in an ArrayList instance. That means we will reverse the order of the elements in a specified range within an ArrayList object. Here we will use the ArrayList class Reverse() method to reverse a range of element’s order. The ArrayList Reverse() method reverses the order of the elements in the ArrayList or a port...

c# - How to remove a range of elements from ArrayList

Remove a range of elements from an ArrayList The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can remove a range of elements from an ArrayList instance at once. That means we will delete multiple elements from an ArrayList object. Here we will use the ArrayList class RemoveRange() method to remove a range of elements from an ArrayList instance. The ArrayList RemoveRange(Int32, Int32) method removes a range of elements from the ArrayList. The RemoveRange(in...

c# - How to insert multiple elements into an ArrayList

Insert multiple elements into an ArrayList at once The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can insert multiple elements into an ArrayList at once. That means we add a collection of elements into an ArrayList at the specified index position. Here we will use the ArrayList class InsertRange() method to add multiple elements to an ArrayList instance. The ArrayList InsertRange(Int32, ICollection) method inserts the elements of a collection into the Ar...

c# - How to get the index of an element within a range in ArrayList

Get the index of an element within a range of elements in an ArrayList The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can get the index of an element within a range of elements in an ArrayList. That means we will find the specified element within a range of elements in an ArrayList. Here we will use the ArrayList class IndexOf() method to get the index of an element within a range in an ArrayList object. We only take the index of the element’s first occurren...

c# - How to get an element index in ArrayList by the starting index

Get an element index from ArrayList by specified starting index The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can get the index of an element in an ArrayList instance by using the starting index. That means we will find the specified element within ArrayList from the specified index position. Here we will use the ArrayList class IndexOf() method to get the index of an element in an ArrayList object. We only take the index of the element’s first occurrence wit...

c# - How to get the index of an ArrayList element

Get the index of an element in ArrayList The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The ArrayList capacity is the number of elements it can hold. Its capacity is automatically increased while adding elements. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can get the index of an element in an ArrayList instance. Here we will use the ArrayList class IndexOf() method to get the index of an element in an ArrayList object. We only take the index of the element’s first occurrence within an ArrayList. The ArrayList IndexOf() method returns the zero-based index of the first occurrence of a value in the ArrayList or in a porti...

c# - How to copy a range of ArrayList elements to an Array

Copy a range of elements from the ArrayList to an Array The ArrayList class implements the IList interface using an array whose size is dynamically increased as required. It is designed to hold heterogeneous collections of objects. ArrayList is not guaranteed to be sorted. The capacity of an ArrayList is the number of elements the ArrayList can hold. As elements are added to an ArrayList, the capacity is automatically increased. ArrayList elements can be accessed by index and it is zero-based. The ArrayList accepts null as a valid value and also allows duplicate elements. The following .net c# tutorial code demonstrates how we can copy an ArrayList specified elements (a range of elements) to an Array. Here we used the ArrayList class CopyTo() method to copy an ArrayList to an Array instance. The ArrayList CopyTo() method copies the ArrayList or a portion of it to a one-dimensional array. The ArrayList CopyTo(Int32, Array, Int32, Int32) method...