Write a class containing a method with the signature
System.Array ChangeElementType(System.Array jaggedArray)
(you may rename identifiers
jaggedArray and shorten the type
using directives). The class may contain any additional members if needed.
You may assume the following preconditions (and do not need to validate them):
- The argument
- The argument
jaggedArrayis an array instance whose type can be represented in C# notation as
int[...]..., i.e. the type
intfollowed by 1 or more rank specifiers
[...]where each rank specifier is a pair or square brackets with 0 or more commas between them. For example, it could be an array of type
- No element at any level of the
- All elements at any level of the
jaggedArrayare distinct w.r.t. reference equality (i.e. the same array instance does not appear at several different positions).
- The lower bound of any array dimension is 0.
- The length of any dimension and the total number of elements of any array fits into the type
The method must create and return an array of type
long[...]... which is obtained from the type of
jaggedArray by replacing
long and keeping all rank specifiers the same. The result must have the same shape as
jaggedArray, i.e. all array dimensions at any level must be the same. All elements at the innermost level must have the same numeric values (cast from
long). The method must not mutate the argument
jaggedArray or any its elements at any level.
The solution may be implemented in any language for the .NET platform: C#, F#, VB.NET, MSIL, C++/CLI, etc. All necessary
imports directives or fully qualified names must be explicitly specified (do not rely on IDE defaults). The only referenced assembly must be
mscorlib, no P/Invoke or COM Interop allowed. The solution cannot access any Internet services to get the result, intermediate data or to download parts of an algorithm.
It is a golf — try to minimize the number of bytes in the source.