CastArray3DTFrom, TTo Structure

Represents a cubic (three-dimensional) array backed by a single-dimensional array of element type TFrom where the reinterpreted element type is cast to TTo. It supports accessing its planes as CastArray2DTFrom, TTo instances, or the whole content as a single dimensional CastArrayTFrom, TTo. Depending on the used platform the reinterpreted elements can also be accessed as a SpanT.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
[SerializableAttribute]
public readonly struct CastArray3D<TFrom, TTo> : IEquatable<CastArray3D<TFrom, TTo>>, 
	IEnumerable<TTo>, IEnumerable
where TFrom : struct, new()
where TTo : struct, new()
Inheritance
Object    ValueType    CastArray3DTFrom, TTo
Implements
IEnumerableTTo, IEnumerable, IEquatableCastArray3DTFrom, TTo

Type Parameters

TFrom
The actual element type of the underlying array.
TTo
The reinterpreted element type of the underlying array.

Remarks

In .NET Core 2.1/.NET Standard 2.1 and above a CastArray3DTFrom, TTo instance can be easily turned to a SpanT instance (either by cast or by the AsSpan property).

The single dimensional buffer can be accessed by the Buffer property that returns a CastArrayTFrom, TTo structure. The actual underlying single dimensional array can be accessed via its Buffer property that returns an ArraySectionT structure and has an UnderlyingArray property.

Unlike Array3DT, CastArray3DTFrom, TTo has no self-allocating constructors and it does not implement the IDisposable interface. But you can pass an ArraySectionT instance to the constructor that allocated a buffer by itself. In such case it's the caller's responsibility to call the Release method in the end to return the possibly rented array to the pool.

  Tip

See more details and some examples about KGy SOFT's span-like types at the Remarks section of the ArraySectionT type.

Constructors

CastArray3DTFrom, TTo(ArraySectionTFrom, Int32, Int32, Int32) Initializes a new instance of the CastArray3DTFrom, TTo struct from an existing ArraySectionT using the specified depth, height and width.
CastArray3DTFrom, TTo(CastArrayTFrom, TTo, Int32, Int32, Int32) Initializes a new instance of the CastArray3DTFrom, TTo struct from an existing CastArrayTFrom, TTo using the specified depth, height and width.

Properties

AsMemory Returns this CastArray3DTFrom, TTo as a MemoryT instance. Please note that getting this property allocates a custom MemoryManagerT instance on the heap internally.
AsSpan Returns this CastArray3DTFrom, TTo as a SpanT instance.
Buffer Gets the underlying buffer as a single dimensional CastArrayTFrom, TTo.
Depth Gets the depth of this CastArray3DTFrom, TTo instance.
Height Gets the height of this CastArray3DTFrom, TTo instance.
IsNull Gets whether this CastArray3DTFrom, TTo instance represents a array.
Please note that the ToArray/To3DArray/ToJaggedArray methods return when this property returns .
IsNullOrEmpty Gets whether this CastArray3DTFrom, TTo instance represents an empty or a array.
ItemIndex Gets a plane of the CastArray3DTFrom, TTo as a CastArray2DTFrom, TTo instance. Please note that the size of TTo multiplied by Width times Height must be divisible by the size of TFrom.
ItemInt32 Gets a plane of the CastArray3DTFrom, TTo as a CastArray2DTFrom, TTo instance. Please note that the size of TTo multiplied by Width times Height must be divisible by the size of TFrom.
ItemRange Gets a new CastArray3DTFrom, TTo instance, which represents a subrange of planes of the current instance indicated by the specified range. Please note that the size of TTo multiplied by Width times Height must be divisible by the size of TFrom.
ItemInt32, 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.
Length Gets the total number of TTo elements in this CastArray3DTFrom, TTo instance.
Width Gets the width of this CastArray3DTFrom, TTo instance.

Methods

Equals(CastArray3DTFrom, TTo) Indicates whether the current CastArray3DTFrom, TTo 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 indices. Parameter order is the same as in case of a regular three-dimensional array.
GetElementReferenceUnsafe Gets the reference to the element at the specified coordinates without any range check or validation. This method can even throw a NullReferenceException if the IsNull property returns . To validate the coordinates against Length use the GetElementReference method instead. Parameter order is the same as in case of a regular three-dimensional array.
GetElementUnsafe Gets the element at the specified indices without any range check or validation. This method can even throw a NullReferenceException if the IsNull property returns . To validate the coordinates against Length use the appropriate indexer instead. Parameter order is the same as in case of a regular three-dimensional array.
GetEnumerator Returns an enumerator that iterates through the items of this CastArray3DTFrom, TTo.
GetHashCode Returns a hash code for this CastArray3DTFrom, TTo instance.
(Overrides ValueTypeGetHashCode)
GetPinnableReference Returns a reference to the first element in this CastArray3DTFrom, TTo. This makes possible to use the CastArray3DTFrom, TTo in a fixed statement.
SetElementUnsafe Sets the element at the specified indices without any range check or validation. This method can even throw a NullReferenceException if the IsNull property returns . To validate the coordinates against Length use the appropriate indexer instead. Parameter order is the same as in case of a regular three-dimensional array.
Slice(Int32) Gets a new CastArray3DTFrom, TTo instance, which represents a subrange of planes of the current instance starting with the specified startPlaneIndex. Please note that the size of TTo multiplied by Width times Height must be divisible by the size of TFrom.
Slice(Int32, Int32) Gets a new CastArray3DTFrom, TTo instance, which represents a subrange of planes of the current instance starting with the specified startPlaneIndex and planeCount. Please note that the size of TTo multiplied by Width times Height must be divisible by the size of TFrom.
To3DArray Copies the elements of this CastArray3DTFrom, TTo to a new three-dimensional array of element type TTo.
ToArray Copies the elements of this CastArray3DTFrom, TTo to a new single dimensional array of element type TTo.
ToJaggedArray Copies the elements of this CastArray3DTFrom, TTo to a new jagged array of element type TTo.

Operators

Equality(CastArray3DTFrom, TTo, CastArray3DTFrom, TTo) Determines whether two specified CastArray3DTFrom, TTo instances have the same value.
(CastArray3DTFrom, TTo to SpanTTo) Performs an implicit conversion from CastArray3DTFrom, TTo to SpanT.
Inequality(CastArray3DTFrom, TTo, CastArray3DTFrom, TTo) Determines whether two specified CastArray3DTFrom, TTo instances have different values.

Extension Methods

Convert 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)
ConvertTTarget Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions)
ForEachTTo Similarly to the List<T>.ForEach method, processes an action on each element of an enumerable collection.
(Defined by EnumerableExtensions)
GetRandomElementTTo Gets a random element from the enumerable source using a new FastRandom instance.
(Defined by EnumerableExtensions)
GetRandomElementTTo 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.
See the Examples section of the generic InT(T, T) overload for an example.
(Defined by ObjectExtensions)
IndexOf Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions)
IndexOf Searches for an element in the source enumeration.
(Defined by EnumerableExtensions)
IndexOfTTo Searches for an element in the source enumeration.
(Defined by EnumerableExtensions)
IndexOfTTo Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions)
IsNullOrEmpty Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions)
IsNullOrEmptyTTo Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions)
JoinTTo Concatenates the items of the source collection into a new string instance using the specified separator between the items.
(Defined by EnumerableExtensions)
JoinTTo Concatenates the items of the source collection into a new string instance using the specified separator between the items.
(Defined by EnumerableExtensions)
ShuffleTTo Shuffles an enumerable source (randomizes its elements) using a new FastRandom instance.
(Defined by EnumerableExtensions)
ShuffleTTo Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions)
ShuffleTTo Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions)
ShuffleTTo Shuffles an enumerable source (randomizes its elements) using a specified Random instance.
(Defined by EnumerableExtensions)
ToCircularListTTo Creates a CircularListT from an IEnumerableT.
(Defined by EnumerableExtensions)
ToStringKeyedDictionaryTTo Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified keySelector delegate and a comparer.
(Defined by EnumerableExtensions)
ToStringKeyedDictionaryTTo, TValue Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified key and value selector delegates and a comparer.
(Defined by EnumerableExtensions)
TryAdd Tries to add the specified item to the collection.
(Defined by EnumerableExtensions)
TryAddTTo Tries to add the specified item to the collection.
(Defined by EnumerableExtensions)
TryAddRange Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions)
TryAddRangeTTo Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions)
TryClear Tries to remove all elements from the collection.
(Defined by EnumerableExtensions)
TryClearTTo Tries to remove all elements from the collection.
(Defined by EnumerableExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvertTTarget 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)
TryConvertTTarget 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)
TryGetCount Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions)
TryGetCountTTo Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions)
TryGetElementAt Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions)
TryGetElementAtTTo Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions)
TryInsert Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions)
TryInsertTTo Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions)
TryInsertRange Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions)
TryInsertRangeTTo Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions)
TryRemove Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions)
TryRemoveTTo Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions)
TryRemoveAt Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions)
TryRemoveAtTTo Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions)
TryRemoveRange Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions)
TryRemoveRangeTTo Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions)
TryReplaceRange 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)
TryReplaceRangeTTo 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 Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions)
TrySetElementAtTTo Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions)

See Also