xtd 0.2.0
Loading...
Searching...
No Matches

◆ get_range()

template<typename type_t , typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
list xtd::collections::generic::list< type_t, allocator_t >::get_range ( size_type  index,
size_type  count 
)
inline

Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.

Parameters
indexThe zero-based xtd::collections::generic::list <type_t> index at which the range starts.
countThe number of elements in the range.
Returns
A shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Exceptions
xtd::argument_exceptionindex and count do ! denote a valid range of elements in the xtd::collections::generic::list <type_t>.
Examples
The following code example demonstrates the xtd::collections::generic::list::get_range method and other methods of the xtd::collections::generic::list <type_t> class that act on ranges. At the end of the code example, the xtd::collections::generic::list::get_range method is used to get three items from the list, beginning with index location 2. The xtd::collections::generic::ist::to_array method is called on the resulting xtd::collections::generic::list <type_t>, creating an array of three elements. The elements of the array are displayed.
Remarks
A shallow copy of a collection of reference types, or a subset of that collection, contains only the references to the elements of the collection. The objects themselves are ! copied. The references in the new list point to the same objects as the references in the original list.
A shallow copy of a collection of value types, or a subset of that collection, contains the elements of the collection. However, if the elements of the collection contain references to other objects, those objects are ! copied. The references in the elements of the new collection point to the same objects as the references in the elements of the original collection.
In contrast, a deep copy of a collection copies the elements and everything directly or indirectly referenced by the elements.
This method is an O(n) operation, where n is count.