See the Remarks section for details.
Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.0.0-preview.3
[SerializableAttribute] public struct ArraySection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IEquatable<ArraySection<T>>, ISerializable, IReadOnlyList<T>, IReadOnlyCollection<T>
Type Parameters
- T
- The type of the elements in the collection.
The ArraySectionT type exposes the following members.
Name | Description | |
---|---|---|
![]() | ArraySectionT(T) |
Initializes a new instance of the ArraySectionT struct from the specified array.
No heap allocation occurs when using this constructor overload.
|
![]() | ArraySectionT(T, Int32) |
Initializes a new instance of the ArraySectionT struct from the specified array
using the specified offset.
No heap allocation occurs when using this constructor overload.
|
![]() | ArraySectionT(Int32, Boolean) |
Initializes a new instance of the ArraySectionT struct using an internally allocated buffer.
When using this overload, the returned ArraySectionT instance must be released by the Release method if it is not used anymore. |
![]() | ArraySectionT(T, Int32, Int32) |
Initializes a new instance of the ArraySectionT struct from the specified array
using the specified offset and length.
No heap allocation occurs when using this constructor overload.
|
Name | Description | |
---|---|---|
![]() | AsArraySegment |
Returns the current ArraySectionT instance as an ArraySegmentT.
|
![]() | AsMemory |
Returns the current ArraySectionT instance as a MemoryT instance.
|
![]() | AsSpan |
Returns the current ArraySectionT instance as a SpanT instance.
|
![]() | IsNull |
Gets whether this ArraySectionT instance represents a array.
Please note that the ToArray method returns when this property returns . |
![]() | IsNullOrEmpty |
Gets whether this ArraySectionT instance represents an empty array section or a array.
|
![]() | Item |
Gets or sets the element at the specified index.
To return a reference to an element use the GetElementReference method instead. |
![]() | Length |
Gets the number of elements in this ArraySectionT.
|
![]() | Offset |
Gets the offset, which denotes the start position of this ArraySectionT within the UnderlyingArray.
|
![]() | UnderlyingArray |
Gets the underlying array of this ArraySectionT.
|
Name | Description | |
---|---|---|
![]() | AsArray2D |
Gets this ArraySectionT as an Array2DT instance
using the specified height and width.
The ArraySectionT must have enough capacity for the specified dimensions.
|
![]() | AsArray3D |
Gets this ArraySectionT as an Array3DT instance
using the specified height and width.
The ArraySectionT must have enough capacity for the specified dimensions.
|
![]() | Clear |
Clears the items in this ArraySectionT instance so all elements will have the default value of type T.
|
![]() | Contains |
Determines whether this ArraySectionT contains the specific item.
|
![]() | CopyTo(T, Int32) |
Copies the items of this ArraySectionT to a compatible one-dimensional array, starting at a particular index.
|
![]() | CopyTo(ArraySectionT, Int32) |
Copies the items of this ArraySectionT to a compatible instance, starting at a particular index.
|
![]() | Equals(ArraySectionT) |
Indicates whether the current ArraySectionT instance is equal to another one specified in the other parameter.
|
![]() | Equals(Object) |
Determines whether the specified object is equal to this instance.
(Overrides ValueTypeEquals(Object).) |
![]() | GetElementReference |
Gets the reference to the element at the specified index.
|
![]() | GetEnumerator |
Returns an enumerator that iterates through the items of this ArraySectionT.
|
![]() | GetHashCode |
Returns a hash code for this ArraySectionT instance.
(Overrides ValueTypeGetHashCode.) |
![]() | GetPinnableReference |
Returns a reference to the first element in this ArraySectionT.
This makes possible to use the ArraySectionT in a fixed statement.
|
![]() | IndexOf |
Determines the index of a specific item in this ArraySectionT.
|
![]() | Release |
Releases the underlying array. If this ArraySectionT instance was instantiated by the self allocating constructor,
then this method must be called when the ArraySectionT is not used anymore.
On platforms that do not support the ArrayPoolT class this method simply sets the self instance to Null.
|
![]() | Slice(Int32) |
Gets a new ArraySectionT instance, which represents a subsection of the current instance with the specified startIndex.
|
![]() | Slice(Int32, Int32) |
Gets a new ArraySectionT instance, which represents a subsection of the current instance with the specified startIndex and length.
|
![]() | ToArray |
Copies the elements of this ArraySectionT to a new array.
|
Name | Description | |
---|---|---|
![]() ![]() | Equality |
Determines whether two specified ArraySectionT instances have the same value.
|
![]() ![]() | (T to ArraySectionT) |
Performs an implicit conversion from array of T to ArraySectionT.
|
![]() ![]() | (ArraySectionT to SpanT) |
Performs an implicit conversion from ArraySectionT to Span<T>.
|
![]() ![]() | Inequality |
Determines whether two specified ArraySectionT instances have different values.
|
Name | Description | |
---|---|---|
![]() ![]() | Empty |
Represents the empty ArraySectionT. This field is read-only.
|
![]() ![]() | Null |
Represents the ArraySectionT. This field is read-only.
|
Name | Description | |
---|---|---|
![]() | AddRangeT | (Defined by CollectionExtensions.) |
![]() | AsThreadSafeT | Overloaded.
Returns a LockingListT, which provides a thread-safe wrapper for the specified list.
This only means that if the members are accessed through the returned LockingListT, then the inner state of the wrapped list remains always consistent and not that all of the multi-threading concerns can be ignored.
(Defined by ListExtensions.)See the Remarks section of the LockingListT class for details and some examples. |
![]() | AsThreadSafeT | Overloaded.
Returns a LockingCollectionT, which provides a thread-safe wrapper for the specified collection.
This only means that if the members are accessed through the returned LockingCollectionT, then the inner state of the wrapped collection remains always consistent and not that all of the multi-threading concerns can be ignored.
(Defined by CollectionExtensions.)See the Remarks section of the LockingCollectionT class for details and some examples. |
![]() | Convert(Type, CultureInfo) | Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example. |
![]() ![]() | ConvertTTarget(CultureInfo) | Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Remarks section for details. |
![]() | ForEachT |
Similarly to the List<T>.ForEach method, processes an action on each element of an enumerable collection.
(Defined by EnumerableExtensions.) |
![]() | GetRandomElementT(Boolean) | Overloaded.
Gets a random element from the enumerable source using a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | GetRandomElementT(Random, Boolean) | Overloaded.
Gets a random element from the enumerable source using a specified Random instance.
(Defined by EnumerableExtensions.) |
![]() | In |
Gets whether item is among the elements of set.
(Defined by ObjectExtensions.)See the Examples section of the generic InT(T, T) overload for an example. |
![]() | IndexOf(FuncObject, Boolean) | Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.) |
![]() | IndexOf(Object) | Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.) |
![]() | IndexOfT(T) | Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.) |
![]() | IndexOfT(FuncT, Boolean) | Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.) |
![]() | InsertRangeT | (Defined by ListExtensions.) |
![]() | IsNullOrEmpty | Overloaded.
Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions.) |
![]() | IsNullOrEmptyT | Overloaded.
Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions.) |
![]() | JoinT(Char) | Overloaded.
Concatenates the items of the source collection into a new string instance
using the specified separator between the items.
(Defined by EnumerableExtensions.) |
![]() | JoinT(String) | Overloaded.
Concatenates the items of the source collection into a new string instance
using the specified separator between the items.
(Defined by EnumerableExtensions.) |
![]() | RemoveRangeT |
Removes count amount of items from the specified collection at the specified index.
(Defined by ListExtensions.) |
![]() | ReplaceRangeT |
Removes count amount of items from the target IListT at the specified index, and
inserts the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by ListExtensions.) |
![]() | ShuffleT | Overloaded.
Shuffles an enumerable source (randomizes its elements) using a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleT(Guid) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleT(Int32) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleT(Random) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using a specified Random instance.
(Defined by EnumerableExtensions.) |
![]() | ToCircularListT |
Creates a CircularListT from an IEnumerableT.
(Defined by EnumerableExtensions.) |
![]() | ToStringKeyedDictionaryT(FuncT, String, StringSegmentComparer) | Overloaded.
Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified keySelector delegate and a comparer.
(Defined by EnumerableExtensions.) |
![]() | ToStringKeyedDictionaryT, TValue(FuncT, String, FuncT, TValue, StringSegmentComparer) | Overloaded.
Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified key and value selector delegates and a comparer.
(Defined by EnumerableExtensions.) |
![]() | TryAdd(Object, Boolean, Boolean) | Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddT(T, Boolean, Boolean) | Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddRange(IEnumerable, Boolean, Boolean) | Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddRangeT(IEnumerableT, Boolean, Boolean) | Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryClear(Boolean, Boolean) | Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryClearT(Boolean, Boolean) | Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryConvert(Type, Object) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvert(Type, CultureInfo, Object) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvertTTarget(TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvertTTarget(CultureInfo, TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryGetCount(Int32) | Overloaded.
Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions.) |
![]() | TryGetCountT(Int32) | Overloaded.
Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions.) |
![]() | TryGetElementAt(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TryGetElementAtT(Int32, T, Boolean, Boolean) | Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsert(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertT(Int32, T, Boolean, Boolean) | Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertRange(Int32, IEnumerable, Boolean, Boolean) | Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertRangeT(Int32, IEnumerableT, Boolean, Boolean) | Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemove(Object, Boolean, Boolean) | Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveT(T, Boolean, Boolean) | Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveAt(Int32, Boolean, Boolean) | Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveAtT(Int32, Boolean, Boolean) | Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveRange(Int32, Int32, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveRangeT(Int32, Int32, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.) |
![]() | TryReplaceRange(Int32, Int32, IEnumerable, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the target at the specified index, and
to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.) |
![]() | TryReplaceRangeT(Int32, Int32, IEnumerableT, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the target at the specified index, and
to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.) |
![]() | TrySetElementAt(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TrySetElementAtT(Int32, T, Boolean, Boolean) | Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
The ArraySectionT type is similar to the combination of the MemoryT type and the .NET Core version of the ArraySegmentT type.
In .NET Core 2.1/.NET Standard 2.1 and above an ArraySectionT instance can be easily turned to a SpanT instance (either by cast or by the AsSpan property), which is much faster than using the Span property of a MemoryT instance.
If an ArraySectionT is created by the constructor with a specified size, then depending on the size and the current platform the underlying array might be obtained by using the ArrayPoolT.
![]() |
---|
An ArraySectionT instance that was instantiated by the self allocating constructor must be released by calling the Release method when it is not used anymore. The ArraySectionT type does not implement IDisposable because releasing is not required when ArraySectionT is created from an existing array but not calling it when it would be needed may lead to decreased application performance. |
Though ArraySectionT is practically immutable (has only readonly fields) it is not marked as readonly, which is needed for the Release method to work properly. As ArraySectionT is a non-readonly struct it is not recommended to use it as a readonly field; otherwise, accessing its members would make the pre-C# 8.0 compilers to create defensive copies, which leads to a slight performance degradation.