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.
Namespace: KGySoft.CoreLibrariesAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
public static CastArray<TFrom, TTo> Cast<TFrom, TTo>(
this ArraySegment<TFrom> arraySegment
)
where TFrom : struct, new()
where TTo : struct, new()
<ExtensionAttribute>
Public Shared Function Cast(Of TFrom As {Structure, New}, TTo As {Structure, New}) (
arraySegment As ArraySegment(Of TFrom)
) As CastArray(Of TFrom, TTo)
public:
[ExtensionAttribute]
generic<typename TFrom, typename TTo>
where TFrom : value class, gcnew()
where TTo : value class, gcnew()
static CastArray<TFrom, TTo> Cast(
ArraySegment<TFrom> arraySegment
)
[<ExtensionAttribute>]
static member Cast :
arraySegment : ArraySegment<'TFrom> -> CastArray<'TFrom, 'TTo> when 'TFrom : struct, new() when 'TTo : struct, new()
- arraySegment ArraySegmentTFrom
- The array to create the CastArrayTFrom, TTo from.
- TFrom
- The actual element type of the specified arraySegment.
- TTo
- The reinterpreted element type after casting.
CastArrayTFrom,
TToA
CastArrayTFrom, TTo instance for the specified
arraySegment.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).
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.