ArrayExtensionsCastTFrom, TTo(TFrom) Method
Reinterprets the specified
array 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 TFrom[]? array
)
where TFrom : struct, new()
where TTo : struct, new()
<ExtensionAttribute>
Public Shared Function Cast(Of TFrom As {Structure, New}, TTo As {Structure, New}) (
array As 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(
array<TFrom>^ array
)
[<ExtensionAttribute>]
static member Cast :
array : 'TFrom[] -> CastArray<'TFrom, 'TTo> when 'TFrom : struct, new() when 'TTo : struct, new()
- array TFrom
- The array to create the CastArrayTFrom, TTo from.
- TFrom
- The actual element type of the specified array.
- TTo
- The reinterpreted element type after casting.
CastArrayTFrom,
TToA
CastArrayTFrom, TTo instance for the specified
array.In Visual Basic and C#, you can call this method as an instance method on any object of type
TFrom. 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 array to prevent exceeding beyond the available buffer.