ArrayExtensionsCastTFrom, TTo(ArraySegmentTFrom) Method

Reinterprets the specified arraySegment by returning a CastArrayTFrom, TTo struct, so its element type is cast from TFrom to TTo. No heap allocation occurs when using this method.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static CastArray<TFrom, TTo> Cast<TFrom, TTo>(
	this ArraySegment<TFrom> arraySegment
)
where TFrom : struct, new()
where TTo : struct, new()

Parameters

arraySegment  ArraySegmentTFrom
The array to create the CastArrayTFrom, TTo from.

Type Parameters

TFrom
The actual element type of the specified arraySegment.
TTo
The reinterpreted element type after casting.

Return Value

CastArrayTFrom, TTo
A CastArrayTFrom, TTo instance for the specified arraySegment.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type ArraySegmentTFrom. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

If the size of TTo cannot be divided by the size of TFrom, then the cast result may not cover the whole original arraySegment to prevent exceeding beyond the available buffer.

See Also