KGy SOFT

Array3DT Structure

KGy SOFT Core Libraries Help
Represents a cubic array, whose indexer access is faster than a regular 3D array. It supports accessing its planes as Array2DT instances, or the whole content as a single dimensional ArraySectionT. Depending on the used platform it supports ArrayPool allocation and casting to Span.
See the Remarks section for details.

Namespace:  KGySoft.Collections
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.3.0
Syntax

[SerializableAttribute]
public struct Array3D<T> : IDisposable, IEquatable<Array3D<T>>, 
	IEnumerable<T>, IEnumerable

Type Parameters

T
The type of the elements in the collection.

The Array3DT type exposes the following members.

Constructors

  NameDescription
Public methodArray3DT(Int32, Int32, Int32)
Initializes a new instance of the Array3DT struct using the specified depth, height and width. Parameter order is the same as in case of instantiating a regular three-dimensional array.
If the created Array3DT is not used anymore the Dispose method should be called to return the possibly ArrayPool-allocated underlying buffer to the pool.
Public methodArray3DT(ArraySectionT, Int32, Int32, Int32)
Initializes a new instance of the Array3DT struct from an existing ArraySectionT using the specified depth, height and width. No heap allocation occurs when using this constructor overload.
Top
Properties

  NameDescription
Public propertyAsMemory
Returns the current Array3DT instance as a Memory instance.
Public propertyAsSpan
Returns the current Array3DT instance as a Span instance.
Public propertyBuffer
Public propertyDepth
Gets the depth of this Array3DT instance.
Public propertyHeight
Gets the height of this Array3DT instance.
Public propertyIsNull
Gets whether this Array3DT instance represents a  array.
Please note that the ToArray/To3DArray/ToJaggedArray methods return  when this property returns .
Public propertyIsNullOrEmpty
Gets whether this Array3DT instance represents an empty or a  array.
Public propertyItemIndex
Gets a plane of the Array3DT as an Array2DT instance.
Public propertyItemInt32
Gets a plane of the Array3DT as an Array2DT instance.
Public propertyItemRange
Gets a new Array3DT instance, which represents a subrange of planes of the current instance indicated by the specified range.
Public propertyItemInt32, Int32, Int32
Gets or sets the element at the specified indices. Parameter order is the same as in case of a regular three-dimensional array.
To return a reference to an element use the GetElementReference method instead.
Public propertyLength
Gets the total length of this Array3DT instance.
Public propertyWidth
Gets the width of this Array3DT instance.
Top
Methods

  NameDescription
Public methodDispose
Releases the underlying buffer. If this Array3DT instance was instantiated by the self allocating constructor, then this method must be called when the Array3DT is not used anymore. On platforms that do not support the ArrayPool class this method simply clears the self instance.
Public methodEquals(Object)
Determines whether the specified object is equal to this instance.
(Overrides ValueTypeEquals(Object).)
Public methodEquals(Array3DT)
Indicates whether the current Array3DT instance is equal to another one specified in the other parameter.
Public methodGetElementReference
Gets the reference to the element at the specified indices. Parameter order is the same as in case of a regular three-dimensional array.
Public methodGetEnumerator
Returns an enumerator that iterates through the items of this Array3DT.
Public methodGetHashCode
Returns a hash code for this Array3DT instance.
(Overrides ValueTypeGetHashCode.)
Public methodGetPinnableReference
Returns a reference to the first element in this Array3DT. This makes possible to use the Array3DT in a fixed statement.
Public methodSlice(Int32)
Gets a new Array3DT instance, which represents a subrange of planes of the current instance starting with the specified startPlaneIndex.
Public methodSlice(Int32, Int32)
Gets a new Array3DT instance, which represents a subrange of planes of the current instance indicated by the specified startPlaneIndex and planeCount.
Public methodTo3DArray
Copies the elements of this Array3DT to a new three dimensional array.
Public methodToArray
Copies the elements of this Array3DT to a new single dimensional array.
Public methodToJaggedArray
Copies the elements of this Array3DT to a new jagged array.
Top
Operators

  NameDescription
Public operatorStatic memberEquality
Determines whether two specified Array3DT instances have the same value.
Public operatorStatic member(Array3DT to ArraySectionT)
Performs an implicit conversion from Array3DT to ArraySectionT.
Public operatorStatic member(Array3DT to SpanT)
Performs an implicit conversion from Array3DT to Span<T>.
Public operatorStatic memberInequality
Determines whether two specified Array3DT instances have different values.
Top
Extension Methods

  NameDescription
Public Extension MethodConvert(Type, CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions.)
Public Extension MethodCode exampleConvertTTarget(CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)
Public Extension MethodForEachT
Similarly to the List<T>.ForEach method, processes an action on each element of an enumerable collection.
(Defined by EnumerableExtensions.)
Public Extension MethodGetRandomElementT(Boolean)Overloaded.
Gets a random element from the enumerable source using a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodGetRandomElementT(Random, Boolean)Overloaded.
Gets a random element from the enumerable source using a specified Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodIn (Defined by ObjectExtensions.)
Public Extension MethodIndexOf(FuncObject, Boolean)Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOf(Object)Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOfT(FuncT, Boolean)Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOfT(T)Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.)
Public Extension MethodIsNullOrEmptyOverloaded.
Determines whether the specified source is  or empty (has no elements).
(Defined by EnumerableExtensions.)
Public Extension MethodIsNullOrEmptyTOverloaded.
Determines whether the specified source is  or empty (has no elements).
(Defined by EnumerableExtensions.)
Public Extension MethodJoinT(String)Overloaded.
Concatenates the items of the source collection into a new string instance using the specified separator between the items.
(Defined by EnumerableExtensions.)
Public Extension MethodJoinT(Char)Overloaded.
Concatenates the items of the source collection into a new string instance using the specified separator between the items.
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleTOverloaded.
Shuffles an enumerable source (randomizes its elements) using a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleT(Int32)Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleT(Random)Overloaded.
Shuffles an enumerable source (randomizes its elements) using a specified Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodToCircularListT (Defined by EnumerableExtensions.)
Public Extension MethodTryAdd(Object, Boolean, Boolean)Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddT(T, Boolean, Boolean)Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddRange(IEnumerable, Boolean, Boolean)Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddRangeT(IEnumerableT, Boolean, Boolean)Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryClear(Boolean, Boolean)Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryClearT(Boolean, Boolean)Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryConvert(Type, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, CultureInfo, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(CultureInfo, TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Public Extension MethodTryGetElementAt(Int32, Object, Boolean, Boolean)Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryGetElementAtT(Int32, T, Boolean, Boolean)Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsert(Int32, Object, Boolean, Boolean)Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertT(Int32, T, Boolean, Boolean)Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertRange(Int32, IEnumerable, Boolean, Boolean)Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertRangeT(Int32, IEnumerableT, Boolean, Boolean)Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemove(Object, Boolean, Boolean)Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveT(T, Boolean, Boolean)Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveAt(Int32, Boolean, Boolean)Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveAtT(Int32, Boolean, Boolean)Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveRange(Int32, Int32, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveRangeT(Int32, Int32, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.)
Public Extension MethodTryReplaceRange(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.)
Public Extension MethodTryReplaceRangeT(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.)
Public Extension MethodTrySetElementAt(Int32, Object, Boolean, Boolean)Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTrySetElementAtT(Int32, T, Boolean, Boolean)Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Top
Remarks

In .NET Core 3.0/.NET Standard 2.1 and above an Array3DT instance can be easily turned to a Span instance (either by cast or by the AsSpan property).

If the current platform supports it, the underlying array might be obtained by using the ArrayPool.

Note Note
Unlike the underlying ArraySectionT, the Array3DT implements the IDisposable interface. Calling the Dispose method is required if the Array3DT was not created from an existing ArraySectionT instance. Not calling the Dispose method may lead to decreased application performance.

As Array3DT is a non-readonly struct it is not recommended to use it as a readonly field; otherwise, accessing its members would make the compiler to create a defensive copy, which leads to a slight performance degradation.

See Also

Reference